Android listview上的多个活动可单击

Android listview上的多个活动可单击,android,Android,我的代码iv有一个问题,我一直试图修复这个错误,但仍然没有运气。我希望在单击列表视图中的项目时启动新活动我查找了一段时间后发现了此代码 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch( position ) { case 0: Intent newActivity = new Intent(this, superleague.cl

我的代码iv有一个问题,我一直试图修复这个错误,但仍然没有运气。我希望在单击列表视图中的项目时启动新活动我查找了一段时间后发现了此代码

  public void onItemClick(AdapterView<?> parent, View view,
  int position, long id) {
  switch( position )
  {
   case 0:  Intent newActivity = new Intent(this, superleague.class);     
            startActivity(newActivity);
            break;
   case 1:  Intent newActivity = new Intent(this, youtube.class);     
            startActivity(newActivity);
            break;
   case 2:  Intent newActivity = new Intent(this, olympiakos.class);     
            startActivity(newActivity);
            break;
   case 3:  Intent newActivity = new Intent(this, karaiskaki.class);     
            startActivity(newActivity);
            break;
   case 4:  Intent newActivity = new Intent(this, reservetickets.class);     
            startActivity(newActivity);
            break;
     }
    }
public void onItemClick(AdapterView父视图、视图、,
内部位置,长id){
开关(位置)
{
案例0:Intent newActivity=newintent(这是superleague.class);
星触觉(新活动);
打破
案例1:Intent newActivity=newintent(this,youtube.class);
星触觉(新活动);
打破
案例2:意向新活动=新意向(本,olympiakos.class);
星触觉(新活动);
打破
案例3:Intent newActivity=newintent(这是karaiskaki.class);
星触觉(新活动);
打破
案例4:Intent newActivity=newintent(这是reservetickets.class);
星触觉(新活动);
打破
}
}
现在我把它放在我的项目中,它是问题所在,但由于我是新手,它需要一些时间来解决一些小问题,希望你能帮助

 package com.mybasicapp;

  import android.app.Dialog;
  import android.app.ListActivity;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnCancelListener;
  import android.content.DialogInterface.OnDismissListener;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ImageButton;
  import android.widget.ListView;
  import android.widget.Toast;

  public class menu extends ListActivity implements onListItemClickListner{


  ImageButton ImagebuttonOpenDialog;

   String KEY_TEXTPSS = "TEXTPSS";
   static final int CUSTOM_DIALOG_ID = 0;

    ListView dialog_ListView;

    String[] listContent = {
 "FORD", "BMW", "AUDI", "JAGUAR",
 "MERCEDES", "RENAULT", "ROVER", "SAAB", "BENTLEY",
 "VOLVO", "VAUXHALL", "SEAT"};


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

  ListView lv = getListView();
  lv.setTextFilterEnabled(true);

  lv.setOnListItemClickListener(new OnListItemClickListener() {
  public void onListItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        switch( position )
        {
           case 0:  Intent newActivity = new Intent(this, 
         Pickmodel.class);     
                    startActivity(newActivity);
                    break;
           case 1:  Intent newActivity = new Intent(this, 
         Pickmodel.class);     
                    startActivity(newActivity);
                    break;
           case 2:  Intent newActivity = new Intent(this, 
         Pickmodel.class);     
                    startActivity(newActivity);
                    break;
           case 3:  Intent newActivity = new Intent(this, 
         Pickmodel.class);     
                    startActivity(newActivity);
                    break;
           case 4:  Intent newActivity = new Intent(this, 
         Pickmodel.class);     
                    startActivity(newActivity);
                    break;
        }
      }




   ImagebuttonOpenDialog = (ImageButton)findViewById(R.id.imgbtn1);
   ImagebuttonOpenDialog.setOnClickListener(new Button.OnClickListener(){

    public void onClick(View arg0) {
        showDialog(CUSTOM_DIALOG_ID);
       }});

        }

     @Override
     protected Dialog onCreateDialog(int id) {

      Dialog dialog = null;

      switch(id) {
         case CUSTOM_DIALOG_ID:
          dialog = new Dialog(menu.this);
          dialog.setContentView(R.layout.custom);
          dialog.setTitle("Custom Dialog");

          dialog.setCancelable(true);
          dialog.setCanceledOnTouchOutside(true);

          dialog.setOnCancelListener(new OnCancelListener(){

        public void onCancel(DialogInterface dialog) {
         // TODO Auto-generated method stub
         Toast.makeText(menu.this,
           "OnCancelListener",
           Toast.LENGTH_LONG).show();
        }});

          dialog.setOnDismissListener(new OnDismissListener(){

        public void onDismiss(DialogInterface dialog) {
         // TODO Auto-generated method stub
         Toast.makeText(menu.this,
           "OnDismissListener",
           Toast.LENGTH_LONG).show();
        }});

          //Prepare ListView in dialog
          dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);
          ArrayAdapter<String> adapter
           = new ArrayAdapter<String>(this,
             android.R.layout.simple_list_item_1, listContent);
          dialog_ListView.setAdapter(adapter);
          dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
         // TODO Auto-generated method stub
         Toast.makeText(menu.this,
           parent.getItemAtPosition(position).toString() + " clicked",
           Toast.LENGTH_LONG).show();
         dismissDialog(CUSTOM_DIALOG_ID);
        }});

             break;
         }

      return dialog;
     }

     @Override
     protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
      // TODO Auto-generated method stub
      super.onPrepareDialog(id, dialog, bundle);

      switch(id) {
         case CUSTOM_DIALOG_ID:
          //
             break;
         }

     }

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub

    }

    }


    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
     // TODO Auto-generated method stub

      }
package com.mybasicap;
导入android.app.Dialog;
导入android.app.ListActivity;
导入android.content.DialogInterface;
导入android.content.DialogInterface.OnCancelListener;
导入android.content.DialogInterface.OnDismissListener;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.ImageButton;
导入android.widget.ListView;
导入android.widget.Toast;
公共类菜单扩展ListActivity仅实现ListItemClickListner{
图像按钮图像按钮显示对话框;
字符串键_TEXTPSS=“TEXTPSS”;
静态最终整型自定义对话框ID=0;
ListView对话框\u ListView;
字符串[]listContent={
“福特”、“宝马”、“奥迪”、“捷豹”,
“梅赛德斯”、“雷诺”、“罗孚”、“萨博”、“宾利”,
“沃尔沃”、“沃克斯豪尔”、“座椅”};
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv=getListView();
lv.setTextFilterEnabled(真);
lv.setOnListItemClickListener(新的OnListItemClickListener(){
public void onListItemClick(AdapterView父项、视图、,
内部位置,长id){
开关(位置)
{
案例0:Intent newActivity=新意图(此,
Pickmodel.class);
星触觉(新活动);
打破
案例1:Intent newActivity=新意图(此,
Pickmodel.class);
星触觉(新活动);
打破
案例2:Intent newActivity=新意图(此,
Pickmodel.class);
星触觉(新活动);
打破
案例3:Intent newActivity=新意图(此,
Pickmodel.class);
星触觉(新活动);
打破
案例4:Intent newActivity=新意图(此,
Pickmodel.class);
星触觉(新活动);
打破
}
}
ImageButtonPandialog=(ImageButton)findViewById(R.id.imgbtn1);
ImageButtonOnClickListener.setOnClickListener(新建Button.OnClickListener()){
公共void onClick(视图arg0){
showDialog(自定义对话框ID);
}});
}
@凌驾
受保护的对话框onCreateDialog(int id){
Dialog=null;
开关(id){
案例自定义对话框\u ID:
dialog=新建对话框(菜单。此);
setContentView(R.layout.custom);
对话框.setTitle(“自定义对话框”);
对话框。可设置可取消(true);
对话框。setCanceledOnTouchOutside(true);
setOnCancelListener(新的OnCancelListener(){
public void onCancel(对话框接口对话框){
//TODO自动生成的方法存根
Toast.makeText(menu.this,
“OnCancelListener”,
Toast.LENGTH_LONG).show();
}});
setOnDismissListener(新的OnDismissListener(){
公共void onDismiss(对话框接口对话框){
//TODO自动生成的方法存根
Toast.makeText(menu.this,
“OnDismissListener”,
Toast.LENGTH_LONG).show();
}});
//在对话框中准备ListView
dialog_ListView=(ListView)dialog.findviewbyd(R.id.dialoglist);
阵列适配器
=新阵列适配器(此,
android.R.layout.simple_list_item_1,listContent);
对话框_ListView.setAdapter(适配器);
对话框\u ListView.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//TODO自动生成的方法存根
Toast.makeText(menu.this,
parent.getItemAtPosition(position).toString()+“已单击”,
Toast.LENGTH_LONG).show();
dismissDialog(自定义对话框ID);
}});
打破
}
返回对话框;
}
@凌驾
受保护的void onPrepareDialog(int id、对话框、捆绑包){
//TODO自动生成的方法存根
super.onPrepareDialog(id、对话框、bundle);
开关(id){
案例自定义对话框\u ID:
//
打破
}
}
公共链接(AdapterView arg0、视图arg1、内部arg2、,
长arg3){
//TODO自动生成的方法存根
}
}
公共视图单击(AdapterView arg0、视图arg1、整型arg2、长型arg3){
//TODO自动生成的方法存根
}
如果我遗漏了什么,请告诉我,谢谢 p、 It’我跑不了
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/customdialog"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="20dp"
  android:minWidth="300dp">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/popcar" />

<ListView
    android:id="@+id/dialoglist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/kj" />

</LinearLayout>
<ListView
  android:id="@android:id/list"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >
</ListView>