0

在编写一个不同的类并将其设置为列表视图时,我尝试运行它,但它最终崩溃了,这有点令人失望。想知道我是否可以得到一些帮助!

这是 MainActivity 代码:

public class MainActivity extends Activity 
{
private ListView list;
private ArrayAdapter<String> adapter;
private RibbonMenuView rbmView;
private Button test;
private ListView rbmListView, rbmListView2;
private ArrayAdapter<String> adapt, adapter2;

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /** Init our views **/
    rbmView = (RibbonMenuView) findViewById(R.id.ribbonMenuView1);
    list = (ListView) findViewById(R.id.listView1);

    /** Calls "hideMenu()" after each click similiar to the Facebook or Google+ application **/
    test = (Button) findViewById(R.id.button);
    test.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            // shows how to hide the menu
            if (rbmView != null)
            {
                rbmView.hideMenu();
            }
        }
    });

    /** This is the most important ListView, updating the main list in the Activity **/
    final String[] items_list = { "Shop1", "Shop2", "Shop3" };
    adapt = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items_list);
    rbmListView = (ListView) findViewById(R.id.rbm_listview);
    if (rbmListView != null)
    {
        rbmListView.setOnItemClickListener(new OnItemClickListener() 
        {
            /*
             * (non-Javadoc)
             * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
             */
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
            {
                switch (position)
                {
                case 0:
                    String[] items = { "Location", "Contact", "Appointment" };
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items);
                    break;

                case 1:
                    String[] items1 = { "Location", "Contact", "Appointment" };
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items1);
                    break;

                case 2:
                    String[] items2 = { "Location", "Contact", "Appointment" };
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items2);
                    break;

                /*case 3:
                    String[] items3 = { "Test1", "Test2", "Test3", "Test4" };
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items3);
                    break;*/

                default:
                    String[] itemsd = { "A", "B", "C", "D" };
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, itemsd);
                    break;
                }

                // always update these
                if (list != null)
                {
                    list.setAdapter(adapter);
                }

                if (rbmView != null)
                {
                    rbmView.hideMenu();
                }
            }
        });
        rbmListView.setAdapter(adapt);
    }

    /** This is the second ListView on the menu **/
    final String[] items_list2 = { "About", "Deals", "Contact Developer", };
    adapter2 = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, items_list2);
    rbmListView2 = (ListView) findViewById(R.id.rbm_listview2);
    if (rbmListView2 != null)
    {
        rbmListView2.setOnItemClickListener(new OnItemClickListener()
        {
            /*
             * (non-Javadoc)
             * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
             */
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                switch (position)
                {
                    case 0:
                        String[] items = { "About Goes Here" };
                        adapter = new ArrayAdapter<String>(MainActivity.this,     android.R.layout.simple_list_item_1, items);
                        break;

                    case 1:
                        String[] items1 = { "Deals Goes Here" };
                        adapter = new ArrayAdapter<String>(MainActivity.this,     android.R.layout.simple_list_item_1, items1);
                        break;

                    case 2:
                        startActivity(new Intent(MainActivity.this, ContactDev.class));
                        break;
                }
                Toast.makeText(MainActivity.this, items_list2[position], Toast.LENGTH_SHORT).show();
                if (rbmView != null)
                {
                    rbmView.hideMenu();
                }
            }
        });
        rbmListView2.setAdapter(adapter2);
    }
}

/**  Allows users, even API < 5, to use the back button **/
/*
 * (non-Javadoc)
 * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
 */
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    switch (keyCode)
    {
    case KeyEvent.KEYCODE_BACK:
        // if view is showing, close it
        // all other back button clicks are handled by the phone
        if (rbmView != null)
        {
            if (rbmView.isMenuShowing())
            {
                new Handler().postDelayed(new Runnable()
                {
                    public void run()
                    {
                        rbmView.hideMenu();
                    }
                }, 50);
            } 
            else
            {
                return super.onKeyDown(keyCode, event);
            }
        }
        break;
    default:
        return super.onKeyDown(keyCode, event);

    }

    return true;
}

/*
 * (non-Javadoc)
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 */
public boolean onCreateOptionsMenu(Menu menu) 
{
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

/*
 * (non-Javadoc)
 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
 */
public boolean onOptionsItemSelected(MenuItem item) 
{
    switch (item.getItemId()) 
    {
    case R.id.test:
        // toggle our menu
        if (rbmView != null)
        {
            rbmView.toggleMenu();
        }
        break;

    default:
        return super.onOptionsItemSelected(item);

    }

    return true;
}
}

这是 ContactDev 代码:

public class ContactDev extends Activity {
Button sendEmail;
EditText msg;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_dev);

    sendEmail = (Button) findViewById(R.id.sndBtn);
    sendEmail.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            msg = (EditText) findViewById(R.id.msgTxt);
            String message = msg.getText().toString();
            sendEmail(message);
        }

    });
}

protected void sendEmail(String message) {

    String[] to=new String[]{"Test@email.com"};
    String subject=("Appointment");
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    emailIntent.setType("message/rfc822");
    startActivity(Intent.createChooser(emailIntent, "Gmail"));
}
}

任何帮助都会很好,或者只是在正确方向上的指导也有效!:)

4

1 回答 1

0

我发现了问题所在,这与课程无关。它与 AndroidManifest 有关。我没有将活动添加到导致崩溃的清单中。

于 2013-10-10T13:46:40.393 回答