i have added onClick in my mainactivity for my textview and i had no errors but when i run the app it crashes saying app has stopped working even though i have no errors in my c
You have wrongly initialized your TextView
As you have added TextView
in your layout and you are trying to initialize it with LinearLayout
which is wrong.
Change the LinearLayout
with TextView
in your onCreate() as below :
someLayout = (TextView) findViewById(R.id.state2);
Why are you inflating your layout two times in your code ? I do not understand why are you doing so. But i am providing the code with some relevant code try with my code.
public class MainActivity extends Activity {
private LayoutInflater inflater;
private TextView someLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
someLayout = (TextView) findViewById(R.id.state2); //layout present in activity_main
// inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
runNextTask();
}
public void runNextTask(){
// LinearLayout mInflatedLayout = (LinearLayout) inflater.inflate(R.layout.activity_main, null);
@SuppressWarnings("unused")
final TrackerInfo newInfo = new TrackerInfo();
//set up for model selection
// TextView modelTextview = (TextView)mInflatedLayout.findViewById(R.id.state2);
//someLayout.addView(mInflatedLayout);
someLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
FYI You can not add any layout in TextView
as its View
not a Layout
and in your code i have seen that you are trying to add Layout
into View
which is wrong.