2

次のコードでは、pwd を onclick イベントに渡す方法

String pwd ="/root";   

final ListView lv = (ListView) findViewById(R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {   
  public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng)
        Toast.makeText(MainActivity.this,pwd , Toast.LENGTH_SHORT).show();
    }

編集1:

final String pwd = null;

string pwd ="root"; //Error remove final keyword
final ListView lv = (ListView) findViewById(R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {   
   public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng)
        Toast.makeText(MainActivity.this,pwd , Toast.LENGTH_SHORT).show();
    }
4

4 に答える 4

1

MACの提案に従ってpwdをGlobleとして宣言すると、問題@MACが解決されました

于 2012-10-01T10:07:57.743 に答える
0

これは私が一度やった方法です

public class NatigationOnClick implements OnClickListener {

    String title;
    String html;
    private QuickActionWeb webQuickAction;
    private Context context;
    private View row;

    public NatigationOnClick(String title, String html, Context context,
            View row) {
        this.title = title;
        this.html = html;
        this.context = context;
        this.row = row;
    }

    public void onClick(View v) {

        webQuickAction = new QuickActionWeb(context, QuickActionWeb.VERTICAL,
                title + "<br/>" + html);
        webQuickAction.show(row);

    }

}

今...

view.setOnClickListener(new NatigationOnClick(title, html, context, row));

その助けを願って

于 2012-09-26T11:16:58.510 に答える
0

多分これはあなたを助けるでしょう:

final ListView lv = (ListView) findViewById(R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(MainActivity.this, getPwd(), Toast.LENGTH_SHORT).show();
        }
});


String pwd = "root";

private String getPwd()
{
    return pwd;
}
于 2012-09-26T11:42:54.017 に答える
0

onCreate メソッドの上で String pwd を宣言します。

class demo extends Activity
{String pwd;
onCreate()
{pwd="/root";
final ListView lv = (ListView) findViewById(R.id.list);

lv.setOnItemClickListener(new OnItemClickListener() {   
public void onClick(View arg0) {
Toast.makeText(MainActivity.this,pwd , Toast.LENGTH_SHORT).show();

    }
        }
于 2012-09-26T11:12:36.613 に答える