我的ListView怎么写让每个Item点击事件是跳到不同的Activity

张铮 发布于 2013/06/01 14:08
阅读 3K+
收藏 0
package wolf.test;

import java.util.ArrayList;
import java.util.HashMap;

import wolf.love_1.Love_1_1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Love extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.love);
ListView list = (ListView)findViewById(R.id.lovelist);
ArrayList<HashMap<String,String>> listItem = new ArrayList<HashMap<String,String>>();
HashMap<String,String> m1= new HashMap<String,String>();
HashMap<String,String> m2= new HashMap<String,String>();
HashMap<String,String> m3= new HashMap<String,String>();
m1.put("text", "1.你是何种恋爱控?");
m2.put("text", "2.你必修啥爱情骗规则?");
m3.put("text", "3.你和他是毕分族吗?");
listItem.add(m1);
listItem.add(m2);
listItem.add(m3);
SimpleAdapter ListAdapter = new SimpleAdapter(this, listItem, R.layout.user, new String[]{"text"}, new int[]{R.id.text});
list.setAdapter(ListAdapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

加载中
0
w382285328
w382285328
用BaseAdapter 在getview方法里 加监听
张铮
张铮
能具体点吗?
0
w382285328
w382285328

如果你只是按行的话 也可以直接list.setOnItemClickListener中加判断 

list.setOnItemClickListener(new OnItemClickListener() { 
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) { 
switch(arg2){}//通过arg2来写不同的跳转方法 


});

返回顶部
顶部