Android 如何制作BaseAdapter ListView以在单击行时打开另一个活动?

Android 如何制作BaseAdapter ListView以在单击行时打开另一个活动?,android,listview,android-intent,onclick,baseadapter,Android,Listview,Android Intent,Onclick,Baseadapter,我跟随YouTube上的个人教程,我得到了一切工作。但是,指导人员没有解释在单击行时如何链接BaseAdapter listView以打开另一个活动 以下是我在MainActivity.java中看到的内容 package com.example.baseadapter; public class MainActivity extends Activity { ListView list; @Override protected void onCreate(Bundle savedIns

我跟随YouTube上的个人教程,我得到了一切工作。但是,指导人员没有解释在单击行时如何链接BaseAdapter listView以打开另一个活动

以下是我在MainActivity.java中看到的内容

package com.example.baseadapter;


public class MainActivity extends Activity {

ListView list;

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

    list = (ListView) findViewById(R.id.countries);
    list.setAdapter(new VivzAdapter(this));
}


class SingleRow{

    String title;
    String description;
    int image;
    SingleRow(String title,String description, int image){

        this.title = title;
        this.description = description;
        this.image = image;
    }
}

class VivzAdapter extends BaseAdapter{


    ArrayList<SingleRow> list;
    Context context;
    VivzAdapter(Context c){

        context = c;
        list = new ArrayList<SingleRow>();

        Resources res = c.getResources();

        String[] title = res.getStringArray(R.array.titles);
        String[] description = res.getStringArray(R.array.description);
        int [] images = {
                R.drawable.union_europea,
                R.drawable.espania,
                R.drawable.finlandia,
                R.drawable.francia,
                R.drawable.irlanda,
                R.drawable.italia,
                R.drawable.malta,
                R.drawable.monaco,
                R.drawable.portugal,
                R.drawable.rusia
        };
        for(int i=0;i<10;i++){
            list.add(new SingleRow(title[i],description[i],images[i]));
        }
    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        // TODO Auto-generated method stub
        return list.get(i);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.single_row,viewGroup,false);

        TextView title = (TextView) row.findViewById(R.id.textView1);
        TextView description = (TextView) row.findViewById(R.id.textView2);
        ImageView image = (ImageView) row.findViewById(R.id.imageView1);

        SingleRow temp = list.get(i);

        title.setText(temp.title);
        description.setText(temp.description);
        image.setImageResource(temp.image);


        return row;
    }

}
package com.example.baseadapter;
公共类MainActivity扩展了活动{
列表视图列表;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
列表=(ListView)findViewById(R.id.countries);
list.setAdapter(新VivzAdapter(this));
}
类单列{
字符串标题;
字符串描述;
int图像;
单行(字符串标题、字符串描述、整型图像){
this.title=标题;
this.description=描述;
这个图像=图像;
}
}
类VivzaAdapter扩展了BaseAdapter{
数组列表;
语境;
VivzaAdapter(上下文c){
上下文=c;
列表=新的ArrayList();
Resources res=c.getResources();
String[]title=res.getStringArray(R.array.titles);
String[]description=res.getStringArray(R.array.description);
int[]图像={
R.drawable.union_europea,
R.drawable.espania,
R.drawable.finlandia,
R.drawable.francia,
R.drawable.irlanda,
R.drawable.italia,
R.drawable.malta,
R.drawable.摩纳哥,
R.drawable.葡萄牙,
拉丝罗非鱼
};

对于(int i=0;i您在
视图上实现onClickListener以打开另一个活动

row.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
         Intent intent = new Intent(getContext(), ACTIVITY.class);
         getContext().startActivity(intent);
    }
};
希望这有帮助

row.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
         Intent intent = new Intent(getContext(), ACTIVITY.class);
         getContext().startActivity(intent);
    }
};