我想放两个textview,然后决定点击哪一个开始相应的活动?我不想使用按钮。有什么想法??
答案 0 :(得分:2)
在onCreate
TextView texVar= (TextView) findViewById(R.id.box_Name);
TextView texVar2= (TextView) findViewById(R.id.box_Name2);
texVar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code here ...
Toast.makeText(getApplicationContext(), "Clicked first!!",
Toast.LENGTH_LONG).show();
}
});
texVar2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code here ...
Toast.makeText(getApplicationContext(), "Clicked second!!",
Toast.LENGTH_LONG).show();
}
});
答案 1 :(得分:0)
只需在活动中添加View.onClickListener接口,添加:
textView1.setOnClickListener(this);
到您活动中的每个textView。在onClick(View v)实现中添加:
v.getId();
确定TextView按下的位置。
答案 2 :(得分:0)
你可以试试这个:
TextView name= (TextView) findViewById(R.id.box_Name);
TextView name2= (TextView) findViewById(R.id.box_Name2);
name.setOnTouchListener(new View.OnTouchListener() {
@Override
public void onTouch(View v) {
//code here ...
Toast.makeText(getApplicationContext(), "Clicked first...",
Toast.LENGTH_LONG).show();
}
});
name2.setOnTouchListener(new View.OnTouchListener() {
@Override
public void onTouch(View v) {
//code here ...
Toast.makeText(getApplicationContext(), "Clicked second..",
Toast.LENGTH_LONG).show();
}
});