在我的代码中,我的onItemClick中的结束标记(AdapterView是红色的,我不明白为什么......看看:
public class MyActivity3 extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my3);
Button m = (Button) findViewById(R.id.button3);
tv = (TextView) findViewById(R.id.textViewcat);
Typeface typeface = Typeface.createFromAsset(getAssets(), "BebasNeue Bold.ttf");
tv.setTypeface(typeface);
String listArray[] = new String[] { "All", "Friends & Family", "Sports", "Outside",
"At School", "Fitness", "Photography", "Food", "Beach", "Money" };
ListView listView = (ListView) findViewById(R.id.listView);
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i <= listArray.length - 1; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("title", listArray[i]);
aList.add(hm);
}
String[] sfrm = { "title"};
int[] sto = { R.id.title};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList,
R.layout.row_layout, sfrm, sto);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
CheckBox cb = (CheckBox) view.findViewById(R.id.chk);
cb.setChecked(!cb.isChecked());
}
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.animation8, R.anim.animation7);
}
}
我会非常感激解决方案,这让我感到很生气。在此先感谢... :)
编辑:这是一个筛选:
答案 0 :(得分:2)
您只需关闭一个不需要关闭的}
。
public class MyActivity3 extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my3);
Button m = (Button) findViewById(R.id.button3);
tv = (TextView) findViewById(R.id.textViewcat);
Typeface typeface = Typeface.createFromAsset(getAssets(), "BebasNeue Bold.ttf");
tv.setTypeface(typeface);
String listArray[] = new String[] { "All", "Friends & Family", "Sports", "Outside", "At School", "Fitness", "Photography", "Food", "Beach",
"Money" };
ListView listView = (ListView) findViewById(R.id.listView);
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i <= listArray.length - 1; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("title", listArray[i]);
aList.add(hm);
}
String[] sfrm = { "title" };
int[] sto = { R.id.title };
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.row_layout, sfrm, sto);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
CheckBox cb = (CheckBox) view.findViewById(R.id.chk);
cb.setChecked(!cb.isChecked());
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.animation8, R.anim.animation7);
}