How can I change and reach ListView item text color? [duplicate]












0
















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers



  • diferrence between R & android.R class [duplicate]

    5 answers



  • What is “android.R.id.text1”?

    7 answers




I created a ListView showing todo tasks with ArrayList and ArrayAdapter. When I click one task, it is removing from todo task list and it is added to another ArrayList which is completed todo task list. What I am trying to do is, to add tasks to completed todo task list with a different text color.



I created another XML for completed tasks but I also need to reach text color value to make a comparison for next steps. According to it's color, I will add to do tasks and completed tasks together with another list later, and they are needed to be seen in different colors.



I tried also Overriding getView method to reach setter and getter methods but it gives me an exception (on the text.setTextColor(Color.RED); line below), when I clicked Show Completed Tasks in the app.



I can't figure it out, I hope somebody help me to figure it out:



Application Screenshot



public class MainActivity extends AppCompatActivity {

private DrawerLayout mainLayout;
private AlertDialog.Builder dialogBuilder, confirmBuilder;
private AlertDialog dialog, confirmDialog;
private ArrayList<String> todoList, completedList, allList;
private ArrayAdapter<String> todoAdapter,completedAdapter, allAdapter;
private ListView listView;
private TextView txt;
private boolean isCompletedJob;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

isCompletedJob=false;
listView = findViewById(R.id.listView1);

mainLayout = findViewById(R.id.drawer_layout); //FIND THE LAYOUT INCLUDING MAIN CONTENT AND NAVIGATION MENU

dialogBuilder = new AlertDialog.Builder(this); //CREATE A BUILDER TO CREATE A DIALOG
dialogBuilder.setTitle("Enter a job to do:"); //CREATE DIALOG TITLE

final EditText input = (EditText) new EditText(this); //CREATE TEXT TO ADD BUILDER'S BODY
dialogBuilder.setView(input); //ADD TEXT VIEW INTO DIALOG'S BODY


/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/
dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//OK BUTONA BASILDIĞINDA TODO'YA EKLE
AddTask(input.getText().toString());
input.setText("");

}
});

dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/

dialog = dialogBuilder.create(); //DIALOG'U YARAT

todoList = new ArrayList<>();
todoAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,todoList);

completedList = new ArrayList<>();
completedAdapter = new ArrayAdapter<String>(this,R.layout.simplerow,completedList)/*{
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);


text.setTextColor(Color.RED);


return view;
}
}*/;




NavigationView navigationView = findViewById(R.id.nav_view); //FIND NAVIGATION VIEW'S ID

navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {

if(menuItem.getTitle().toString().startsWith("Add")){
//AddTask();
dialog.show();
}
else if (menuItem.getTitle().toString().startsWith("To")){
ShowToDoTasks();
}
else if (menuItem.getTitle().toString().startsWith("Completed")){
ShowCompletedTasks();
}
else if (menuItem.getTitle().toString().startsWith("All")){
ShowAllTasks();
}
else if (menuItem.getTitle().toString().startsWith("Close")){
CloseProgram();
}
else
return false;
return true;
}
}
);

}

public void ItemClicked(View v){

txt = (TextView) v;

if(!isCompletedJob) {
CreateConfirmDialog();
}
}

public void AddTask(String msg){

Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
todoAdapter.add(msg);
listView.setAdapter(todoAdapter);
isCompletedJob=false;

}

public void ShowCompletedTasks(){
//Toast.makeText(this,"Completed pressed",Toast.LENGTH_LONG).show();
Toast.makeText(this,completedList.size()+"",Toast.LENGTH_LONG).show();
listView.setAdapter(completedAdapter);
isCompletedJob=true;
}

public void ShowAllTasks(){
Toast.makeText(this,"Show All pressed",Toast.LENGTH_LONG).show();

listView.setAdapter(allAdapter);

}

public void ShowToDoTasks(){
Toast.makeText(this,"Show ToDo pressed",Toast.LENGTH_LONG).show();
listView.setAdapter(todoAdapter);
isCompletedJob=false;
}

public void CloseProgram(){
Toast.makeText(this,"Close pressed",Toast.LENGTH_LONG).show();
}

public void UpdateLists(){

txt.setTextColor(Color.RED);
completedAdapter.add(txt.getText().toString());
todoAdapter.remove(txt.getText().toString());

Toast.makeText(MainActivity.this, txt.getText().toString() + " : Done",Toast.LENGTH_LONG).show();

}

public void CreateConfirmDialog(){
/*--- CONFIRMATION IF THE CLICKED JOB COMPLETED OR NOT ---*/
confirmBuilder = new AlertDialog.Builder(this);
confirmBuilder.setTitle("Task Completed? ");

confirmBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UpdateLists();
}
});

confirmBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});

confirmDialog = confirmBuilder.create();
confirmDialog.show();
}
}


Exception:




E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.todoapp, PID: 4825
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at com.example.user.todoapp.MainActivity$3.getView(MainActivity.java:83)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)











share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 0:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

    – Mike M.
    Nov 24 '18 at 23:17











  • @MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:28













  • Change your findViewById() call to pass R.id.text1 instead.

    – Mike M.
    Nov 24 '18 at 23:30











  • you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:33











  • No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

    – Mike M.
    Nov 24 '18 at 23:35
















0
















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers



  • diferrence between R & android.R class [duplicate]

    5 answers



  • What is “android.R.id.text1”?

    7 answers




I created a ListView showing todo tasks with ArrayList and ArrayAdapter. When I click one task, it is removing from todo task list and it is added to another ArrayList which is completed todo task list. What I am trying to do is, to add tasks to completed todo task list with a different text color.



I created another XML for completed tasks but I also need to reach text color value to make a comparison for next steps. According to it's color, I will add to do tasks and completed tasks together with another list later, and they are needed to be seen in different colors.



I tried also Overriding getView method to reach setter and getter methods but it gives me an exception (on the text.setTextColor(Color.RED); line below), when I clicked Show Completed Tasks in the app.



I can't figure it out, I hope somebody help me to figure it out:



Application Screenshot



public class MainActivity extends AppCompatActivity {

private DrawerLayout mainLayout;
private AlertDialog.Builder dialogBuilder, confirmBuilder;
private AlertDialog dialog, confirmDialog;
private ArrayList<String> todoList, completedList, allList;
private ArrayAdapter<String> todoAdapter,completedAdapter, allAdapter;
private ListView listView;
private TextView txt;
private boolean isCompletedJob;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

isCompletedJob=false;
listView = findViewById(R.id.listView1);

mainLayout = findViewById(R.id.drawer_layout); //FIND THE LAYOUT INCLUDING MAIN CONTENT AND NAVIGATION MENU

dialogBuilder = new AlertDialog.Builder(this); //CREATE A BUILDER TO CREATE A DIALOG
dialogBuilder.setTitle("Enter a job to do:"); //CREATE DIALOG TITLE

final EditText input = (EditText) new EditText(this); //CREATE TEXT TO ADD BUILDER'S BODY
dialogBuilder.setView(input); //ADD TEXT VIEW INTO DIALOG'S BODY


/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/
dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//OK BUTONA BASILDIĞINDA TODO'YA EKLE
AddTask(input.getText().toString());
input.setText("");

}
});

dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/

dialog = dialogBuilder.create(); //DIALOG'U YARAT

todoList = new ArrayList<>();
todoAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,todoList);

completedList = new ArrayList<>();
completedAdapter = new ArrayAdapter<String>(this,R.layout.simplerow,completedList)/*{
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);


text.setTextColor(Color.RED);


return view;
}
}*/;




NavigationView navigationView = findViewById(R.id.nav_view); //FIND NAVIGATION VIEW'S ID

navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {

if(menuItem.getTitle().toString().startsWith("Add")){
//AddTask();
dialog.show();
}
else if (menuItem.getTitle().toString().startsWith("To")){
ShowToDoTasks();
}
else if (menuItem.getTitle().toString().startsWith("Completed")){
ShowCompletedTasks();
}
else if (menuItem.getTitle().toString().startsWith("All")){
ShowAllTasks();
}
else if (menuItem.getTitle().toString().startsWith("Close")){
CloseProgram();
}
else
return false;
return true;
}
}
);

}

public void ItemClicked(View v){

txt = (TextView) v;

if(!isCompletedJob) {
CreateConfirmDialog();
}
}

public void AddTask(String msg){

Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
todoAdapter.add(msg);
listView.setAdapter(todoAdapter);
isCompletedJob=false;

}

public void ShowCompletedTasks(){
//Toast.makeText(this,"Completed pressed",Toast.LENGTH_LONG).show();
Toast.makeText(this,completedList.size()+"",Toast.LENGTH_LONG).show();
listView.setAdapter(completedAdapter);
isCompletedJob=true;
}

public void ShowAllTasks(){
Toast.makeText(this,"Show All pressed",Toast.LENGTH_LONG).show();

listView.setAdapter(allAdapter);

}

public void ShowToDoTasks(){
Toast.makeText(this,"Show ToDo pressed",Toast.LENGTH_LONG).show();
listView.setAdapter(todoAdapter);
isCompletedJob=false;
}

public void CloseProgram(){
Toast.makeText(this,"Close pressed",Toast.LENGTH_LONG).show();
}

public void UpdateLists(){

txt.setTextColor(Color.RED);
completedAdapter.add(txt.getText().toString());
todoAdapter.remove(txt.getText().toString());

Toast.makeText(MainActivity.this, txt.getText().toString() + " : Done",Toast.LENGTH_LONG).show();

}

public void CreateConfirmDialog(){
/*--- CONFIRMATION IF THE CLICKED JOB COMPLETED OR NOT ---*/
confirmBuilder = new AlertDialog.Builder(this);
confirmBuilder.setTitle("Task Completed? ");

confirmBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UpdateLists();
}
});

confirmBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});

confirmDialog = confirmBuilder.create();
confirmDialog.show();
}
}


Exception:




E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.todoapp, PID: 4825
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at com.example.user.todoapp.MainActivity$3.getView(MainActivity.java:83)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)











share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 0:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

    – Mike M.
    Nov 24 '18 at 23:17











  • @MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:28













  • Change your findViewById() call to pass R.id.text1 instead.

    – Mike M.
    Nov 24 '18 at 23:30











  • you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:33











  • No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

    – Mike M.
    Nov 24 '18 at 23:35














0












0








0


0







This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers



  • diferrence between R & android.R class [duplicate]

    5 answers



  • What is “android.R.id.text1”?

    7 answers




I created a ListView showing todo tasks with ArrayList and ArrayAdapter. When I click one task, it is removing from todo task list and it is added to another ArrayList which is completed todo task list. What I am trying to do is, to add tasks to completed todo task list with a different text color.



I created another XML for completed tasks but I also need to reach text color value to make a comparison for next steps. According to it's color, I will add to do tasks and completed tasks together with another list later, and they are needed to be seen in different colors.



I tried also Overriding getView method to reach setter and getter methods but it gives me an exception (on the text.setTextColor(Color.RED); line below), when I clicked Show Completed Tasks in the app.



I can't figure it out, I hope somebody help me to figure it out:



Application Screenshot



public class MainActivity extends AppCompatActivity {

private DrawerLayout mainLayout;
private AlertDialog.Builder dialogBuilder, confirmBuilder;
private AlertDialog dialog, confirmDialog;
private ArrayList<String> todoList, completedList, allList;
private ArrayAdapter<String> todoAdapter,completedAdapter, allAdapter;
private ListView listView;
private TextView txt;
private boolean isCompletedJob;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

isCompletedJob=false;
listView = findViewById(R.id.listView1);

mainLayout = findViewById(R.id.drawer_layout); //FIND THE LAYOUT INCLUDING MAIN CONTENT AND NAVIGATION MENU

dialogBuilder = new AlertDialog.Builder(this); //CREATE A BUILDER TO CREATE A DIALOG
dialogBuilder.setTitle("Enter a job to do:"); //CREATE DIALOG TITLE

final EditText input = (EditText) new EditText(this); //CREATE TEXT TO ADD BUILDER'S BODY
dialogBuilder.setView(input); //ADD TEXT VIEW INTO DIALOG'S BODY


/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/
dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//OK BUTONA BASILDIĞINDA TODO'YA EKLE
AddTask(input.getText().toString());
input.setText("");

}
});

dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/

dialog = dialogBuilder.create(); //DIALOG'U YARAT

todoList = new ArrayList<>();
todoAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,todoList);

completedList = new ArrayList<>();
completedAdapter = new ArrayAdapter<String>(this,R.layout.simplerow,completedList)/*{
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);


text.setTextColor(Color.RED);


return view;
}
}*/;




NavigationView navigationView = findViewById(R.id.nav_view); //FIND NAVIGATION VIEW'S ID

navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {

if(menuItem.getTitle().toString().startsWith("Add")){
//AddTask();
dialog.show();
}
else if (menuItem.getTitle().toString().startsWith("To")){
ShowToDoTasks();
}
else if (menuItem.getTitle().toString().startsWith("Completed")){
ShowCompletedTasks();
}
else if (menuItem.getTitle().toString().startsWith("All")){
ShowAllTasks();
}
else if (menuItem.getTitle().toString().startsWith("Close")){
CloseProgram();
}
else
return false;
return true;
}
}
);

}

public void ItemClicked(View v){

txt = (TextView) v;

if(!isCompletedJob) {
CreateConfirmDialog();
}
}

public void AddTask(String msg){

Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
todoAdapter.add(msg);
listView.setAdapter(todoAdapter);
isCompletedJob=false;

}

public void ShowCompletedTasks(){
//Toast.makeText(this,"Completed pressed",Toast.LENGTH_LONG).show();
Toast.makeText(this,completedList.size()+"",Toast.LENGTH_LONG).show();
listView.setAdapter(completedAdapter);
isCompletedJob=true;
}

public void ShowAllTasks(){
Toast.makeText(this,"Show All pressed",Toast.LENGTH_LONG).show();

listView.setAdapter(allAdapter);

}

public void ShowToDoTasks(){
Toast.makeText(this,"Show ToDo pressed",Toast.LENGTH_LONG).show();
listView.setAdapter(todoAdapter);
isCompletedJob=false;
}

public void CloseProgram(){
Toast.makeText(this,"Close pressed",Toast.LENGTH_LONG).show();
}

public void UpdateLists(){

txt.setTextColor(Color.RED);
completedAdapter.add(txt.getText().toString());
todoAdapter.remove(txt.getText().toString());

Toast.makeText(MainActivity.this, txt.getText().toString() + " : Done",Toast.LENGTH_LONG).show();

}

public void CreateConfirmDialog(){
/*--- CONFIRMATION IF THE CLICKED JOB COMPLETED OR NOT ---*/
confirmBuilder = new AlertDialog.Builder(this);
confirmBuilder.setTitle("Task Completed? ");

confirmBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UpdateLists();
}
});

confirmBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});

confirmDialog = confirmBuilder.create();
confirmDialog.show();
}
}


Exception:




E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.todoapp, PID: 4825
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at com.example.user.todoapp.MainActivity$3.getView(MainActivity.java:83)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)











share|improve this question















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers



  • diferrence between R & android.R class [duplicate]

    5 answers



  • What is “android.R.id.text1”?

    7 answers




I created a ListView showing todo tasks with ArrayList and ArrayAdapter. When I click one task, it is removing from todo task list and it is added to another ArrayList which is completed todo task list. What I am trying to do is, to add tasks to completed todo task list with a different text color.



I created another XML for completed tasks but I also need to reach text color value to make a comparison for next steps. According to it's color, I will add to do tasks and completed tasks together with another list later, and they are needed to be seen in different colors.



I tried also Overriding getView method to reach setter and getter methods but it gives me an exception (on the text.setTextColor(Color.RED); line below), when I clicked Show Completed Tasks in the app.



I can't figure it out, I hope somebody help me to figure it out:



Application Screenshot



public class MainActivity extends AppCompatActivity {

private DrawerLayout mainLayout;
private AlertDialog.Builder dialogBuilder, confirmBuilder;
private AlertDialog dialog, confirmDialog;
private ArrayList<String> todoList, completedList, allList;
private ArrayAdapter<String> todoAdapter,completedAdapter, allAdapter;
private ListView listView;
private TextView txt;
private boolean isCompletedJob;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

isCompletedJob=false;
listView = findViewById(R.id.listView1);

mainLayout = findViewById(R.id.drawer_layout); //FIND THE LAYOUT INCLUDING MAIN CONTENT AND NAVIGATION MENU

dialogBuilder = new AlertDialog.Builder(this); //CREATE A BUILDER TO CREATE A DIALOG
dialogBuilder.setTitle("Enter a job to do:"); //CREATE DIALOG TITLE

final EditText input = (EditText) new EditText(this); //CREATE TEXT TO ADD BUILDER'S BODY
dialogBuilder.setView(input); //ADD TEXT VIEW INTO DIALOG'S BODY


/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/
dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//OK BUTONA BASILDIĞINDA TODO'YA EKLE
AddTask(input.getText().toString());
input.setText("");

}
});

dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
/*---DIALOG BUILDER ARACIYLA DIALOG'A OK VE CANCEL BUTONLARI EKLEME---*/

dialog = dialogBuilder.create(); //DIALOG'U YARAT

todoList = new ArrayList<>();
todoAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,todoList);

completedList = new ArrayList<>();
completedAdapter = new ArrayAdapter<String>(this,R.layout.simplerow,completedList)/*{
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);


text.setTextColor(Color.RED);


return view;
}
}*/;




NavigationView navigationView = findViewById(R.id.nav_view); //FIND NAVIGATION VIEW'S ID

navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {

if(menuItem.getTitle().toString().startsWith("Add")){
//AddTask();
dialog.show();
}
else if (menuItem.getTitle().toString().startsWith("To")){
ShowToDoTasks();
}
else if (menuItem.getTitle().toString().startsWith("Completed")){
ShowCompletedTasks();
}
else if (menuItem.getTitle().toString().startsWith("All")){
ShowAllTasks();
}
else if (menuItem.getTitle().toString().startsWith("Close")){
CloseProgram();
}
else
return false;
return true;
}
}
);

}

public void ItemClicked(View v){

txt = (TextView) v;

if(!isCompletedJob) {
CreateConfirmDialog();
}
}

public void AddTask(String msg){

Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
todoAdapter.add(msg);
listView.setAdapter(todoAdapter);
isCompletedJob=false;

}

public void ShowCompletedTasks(){
//Toast.makeText(this,"Completed pressed",Toast.LENGTH_LONG).show();
Toast.makeText(this,completedList.size()+"",Toast.LENGTH_LONG).show();
listView.setAdapter(completedAdapter);
isCompletedJob=true;
}

public void ShowAllTasks(){
Toast.makeText(this,"Show All pressed",Toast.LENGTH_LONG).show();

listView.setAdapter(allAdapter);

}

public void ShowToDoTasks(){
Toast.makeText(this,"Show ToDo pressed",Toast.LENGTH_LONG).show();
listView.setAdapter(todoAdapter);
isCompletedJob=false;
}

public void CloseProgram(){
Toast.makeText(this,"Close pressed",Toast.LENGTH_LONG).show();
}

public void UpdateLists(){

txt.setTextColor(Color.RED);
completedAdapter.add(txt.getText().toString());
todoAdapter.remove(txt.getText().toString());

Toast.makeText(MainActivity.this, txt.getText().toString() + " : Done",Toast.LENGTH_LONG).show();

}

public void CreateConfirmDialog(){
/*--- CONFIRMATION IF THE CLICKED JOB COMPLETED OR NOT ---*/
confirmBuilder = new AlertDialog.Builder(this);
confirmBuilder.setTitle("Task Completed? ");

confirmBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UpdateLists();
}
});

confirmBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});

confirmDialog = confirmBuilder.create();
confirmDialog.show();
}
}


Exception:




E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.todoapp, PID: 4825
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at com.example.user.todoapp.MainActivity$3.getView(MainActivity.java:83)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)






This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers



  • diferrence between R & android.R class [duplicate]

    5 answers



  • What is “android.R.id.text1”?

    7 answers








java android listview arraylist






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 22:57









Doğuşcan YağınlıDoğuşcan Yağınlı

32




32




marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 0:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 0:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

    – Mike M.
    Nov 24 '18 at 23:17











  • @MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:28













  • Change your findViewById() call to pass R.id.text1 instead.

    – Mike M.
    Nov 24 '18 at 23:30











  • you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:33











  • No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

    – Mike M.
    Nov 24 '18 at 23:35



















  • The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

    – Mike M.
    Nov 24 '18 at 23:17











  • @MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:28













  • Change your findViewById() call to pass R.id.text1 instead.

    – Mike M.
    Nov 24 '18 at 23:30











  • you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

    – Doğuşcan Yağınlı
    Nov 24 '18 at 23:33











  • No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

    – Mike M.
    Nov 24 '18 at 23:35

















The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

– Mike M.
Nov 24 '18 at 23:17





The layout used for the ListView items is simplerow. You're trying to find a TextView in that with ID android.R.id.text1. Are you sure that's the ID you set on the TextView in simplerow? It would have to look like android:id="@android:id/text1", if so. If that's not the ID you have set, then change that findViewById() call to use the correct ID.

– Mike M.
Nov 24 '18 at 23:17













@MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

– Doğuşcan Yağınlı
Nov 24 '18 at 23:28







@MikeM. this is the simplerow.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="ItemClicked" android:padding="10dp" android:textSize="16sp" > </TextView>

– Doğuşcan Yağınlı
Nov 24 '18 at 23:28















Change your findViewById() call to pass R.id.text1 instead.

– Mike M.
Nov 24 '18 at 23:30





Change your findViewById() call to pass R.id.text1 instead.

– Mike M.
Nov 24 '18 at 23:30













you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

– Doğuşcan Yağınlı
Nov 24 '18 at 23:33





you are the hero, thanks a lot, It worked! I was struggling with this for 2 hours at least.

– Doğuşcan Yağınlı
Nov 24 '18 at 23:33













No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

– Mike M.
Nov 24 '18 at 23:35





No problem. You just got the system resource IDs mixed up with your own. Anything that starts with android.R is a system resource. Yours start with only R. Anyhoo, glad you got it working. Cheers!

– Mike M.
Nov 24 '18 at 23:35












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno