我正在为以下代码中的列表视图项目分配操作。但是当我单击列表视图项目时,应用程序“不幸停止”。我提供下面的代码。
package com.lara;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class FamilyActivity extends Activity {
private ListView lv;
private String names[]={"sum","hari","mom","dad"};
private ArrayAdapter<String> s1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.family1);
lv=(ListView)findViewById(R.id.listView1);
s1=new ArrayAdapter<String>(getApplication(), R.layout.text, names);
lv.setAdapter(s1);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplication(), 555, Toast.LENGTH_LONG).show();
}
});
}