-1

The app crash because of the following code lines.

I have two string-array in a XML file named as Telephones in a folder named values and two TextView in text.xml.

I can not figure out what's going wrong here.

public class MainActivity extends Activity {
ListView listView;

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

    listView  = (ListView) findViewById(R.id.list);
    String[] name= getResources().getStringArray(R.array.names);
    String[] number= getResources().getStringArray(R.array.numbers);

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.text, name);
    listView.setAdapter(arrayAdapter);
    ArrayAdapter<String> arrayAdapter1= new ArrayAdapter<String>(this, R.layout.text, number);
    listView.setAdapter(arrayAdapter1);
}
 }

Your help would be appreciated.

Thank You!

divy3993
  • 5,732
  • 2
  • 28
  • 41
abood250
  • 3
  • 1
  • 5
  • 2
    Can you edit your question to include your xml files and the stack trace of the crash? – Michiyo Oct 24 '15 at 21:33
  • Post your logcat... and btw, why you set two adapters in the same list??? it's really strange! – Rami Oct 24 '15 at 23:16
  • I don't know actually but I need to a sub item under item in the listview, so I need 2 textview I think,but how can create it? – abood250 Oct 25 '15 at 04:03
  • **No**, ListView not work like that. [Here](http://hmkcode.com/android-custom-listview-items-row/) is an example of ListView with two TextViews. And post your logcat if you want some help in this OP. – Rami Oct 25 '15 at 07:45
  • If I can't how can I add sub items with ArrayAdapter ? because I have a long list – abood250 Oct 25 '15 at 11:52

1 Answers1

0

I forgot to add TextView id in MainActivity java but after adding the names_txt won't show up the only one show up is numbers_txt, how fix it please?

public class MainActivity extends Activity {
ListView listView;

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

    listView  = (ListView) findViewById(R.id.list);
    String[] name= getResources().getStringArray(R.array.names);
    String[] number= getResources().getStringArray(R.array.numbers);

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.text, R.id.names_txt, name);
    listView.setAdapter(arrayAdapter);
    ArrayAdapter<String> arrayAdapter1 = new ArrayAdapter<String>(this, R.layout.text, R.id.numbers_txt, number);
    listView.setAdapter(arrayAdapter1);
}



    }
abood250
  • 3
  • 1
  • 5