here\'s my code for main.xml
add android:clickable="true"
in <TextView>
There is an easy way. Put this in the TextView in XML:
android:clickable="true"
In your onCreate method you need to:
And your class also needs to implement OnClickListener.
public class SqliteTestsActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView all = (TextView) R.findViewById(R.id.viewall);
all.setOnClickListener(this);
}
public void onClick(View v) {
// Fill in this with your switch statement
}
}
Use these
all = (TextView) this.findViewById(R.id.viewall);
pdf = (TextView) this.findViewById(R.id.pic);
in on create and then set
all.setOnclickListener(this) in oncreate() method too.Implement onClicklistener when it will show error. it will work like a charm.
Edited
TextView btn=(TextView) findViewById(R.id.accInfo);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//DO you work here
}
});
Setting Clicklistenner to TextView will automatically make it clickable so no need of
android:clickable="true"
please make changes like this :
<include android:id = "@+id/lyttab" layout="@layout/tabs" />
in your Java class
public void onClick(View v){
View view = findViewById(R.id.lyttab);
all = (TextView) view.findViewById(R.id.viewall);
pif = (TextView) view.findViewById(R.id.pic);
switch (v){
case all :
Toast.makeText(Main.this, "VIEW ALL", Toast.LENGTH_SHORT).show();
all.setTextColor(getResources().getColorStateList(R.color.gradient_green));
pic.setTextColor(getResources().getColorStateList(R.color.white));
break;
case pic:
Toast.makeText(Main.this, "PDF", Toast.LENGTH_SHORT).show();
all.setTextColor(getResources().getColorStateList(R.color.white));
pic.setTextColor(getResources().getColorStateList(R.color.gradient_green));
break;
}
}
i think this will help you