项目单击事件仅在首次创建列表活动时起作用。如果我离开活动或关闭应用程序,该活动将不再有效。仅当我重新安装应用程序时。有什么帮助吗?
MY ACTIVITY
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
String[] fields = new String[] {
"Nome da disciplina",
"Número de faltas permitidas",
"Número de faltas cometidas",
"Hora do término",
"Dias da semana"
};
setListAdapter(new DisciplineFormAdapter(this,fields));
}
protected void onListItemClick(ListView l, View v, int position, long lo){
super.onListItemClick(l, v, position, lo);
Toast.makeText(this, "toast", Toast.LENGTH_SHORT).show();
}
我的适配器
public DisciplineFormAdapter(Context c, String[] l){
this.context = c;
this.fields = l;
}
@Override
public int getCount() {
return fields.length;
}
@Override
public Object getItem(int position) {
return fields[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String field = fields[position];
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_discipline, null);
TextView fieldView = (TextView) v.findViewById(R.id.field);
fieldView.setText(field);
TextView name = (TextView) v.findViewById(R.id.value);
name.setText("value");
return v;
}
我的 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".DisciplineActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/field"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/value" />
</LinearLayout>