刚上班,作为新手,一直在学习。有一点小心得。是关于为listview的item中的控件添加点击事件。listview当然是自定义的。而这个笔记也只是给listview的item中的控件单独做个点击。和listview的onItemClickListener差不多。区别就是可以为item中的多个控件设置点击,比如item中的button,textview,imageview,通过点击可以跳转不同的activity。我要实现的终极目标是点击itme(只有一个textview),每个item跳转的activity都不同。感觉还有好长一段距离。完整代码如下:
activity代码:
public class UseUrl extends Activity{
private Button source;
private ListView datalist;
private ArrayList list = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_url);
source = (Button) findViewById(R.id.btn_open);
source.setOnClickListener(new OnClick());
datalist = (ListView) findViewById(R.id.list_data);
//datalist.setOnItemClickListener(new OnList());
}
private class OnClick implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
InputStream is = getAssets().open("json.xml");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder();
String data = "";