0

我正在尝试为 ListView 中的特定项目创建一个 onItemClickListener。使用此代码,侦听器会对每个项目做出反应,但我只希望它对列表中的一个项目(字体大小)做出反应。

String[] listItems = {"Colour", "Font Size",};
ListView lv = (ListView) findViewById(R.id.settings_list);

lv.setAdapter(new ArrayAdapter<String>
  (this, android.R.layout.simple_list_item_1, listItems));

lv.setOnItemClickListener(new OnItemClickListener()
{
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
            Context context = getApplicationContext();
            CharSequence text = "Clicked";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    });

我如何做到这一点?

提前致谢

4

1 回答 1

1

尝试这个:

 String[] listItems = {"Colour", "Font Size",};
 ListView lv = (ListView) findViewById(R.id.settings_list);

 lv.setAdapter(new ArrayAdapter<String>
 (this, android.R.layout.simple_list_item_1, listItems));

 lv.setOnItemClickListener(new OnItemClickListener()
 {
  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        if(listItems[position].equlas("Font Size"))
        {
          Context context = getApplicationContext();
          CharSequence text = "Clicked";
          int duration = Toast.LENGTH_SHORT;

          Toast toast = Toast.makeText(context, text, duration);
          toast.show();
        }
});
于 2013-10-18T16:40:08.837 回答