listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String str = ((TextView)view).getText().toString();
int x = Integer.parseInt((String)listOutput.getText());
listOutput.setText(Integer.toString(x+1));
TextView t = (TextView)findViewById(R.id.textView);
t.setText("hello");
//Intent openTabbedActivity = new Intent(this,New_tabbed_activity.cl);
}
});
我想在setText()
的{{1}}内使用TextView
类的Intent
类或Intent
构造函数的onItemClick()
方法AdapterView.OnItemClickListener
类
但Android工作室说
MainActivity
同样显示cannot resolve method setText
答案 0 :(得分:0)
试试这段代码:
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String str = ((TextView)view).getText().toString();
int x = Integer.parseInt((String)listOutput.getText());
view.listOutput.setText(Integer.toString(x+1));
TextView t = (TextView)view.findViewById(R.id.textView);
view.t.setText("hello");
//Intent openTabbedActivity = new Intent(this,New_tabbed_activity.cl);
}
});
答案 1 :(得分:0)
通过浏览一些示例,我发现问题是context
在意图中,构造函数的第一个参数应该是MainActivity.this
而不仅仅是this
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String str = ((TextView)view).getText().toString();
int x = Integer.parseInt((String)listOutput.getText());
listOutput.setText(Integer.toString(x+1));
TextView t = (TextView)findViewById(R.id.textView);
MainActiviy.this.t.setText("hello");
Intent openTabbedActivity = new Intent(MainActivity.this,New_tabbed_activity.cl);
}
});