1

I Have a two dimensional string array,

I want to create a 3 column list-view, that display data from the string array, it should have the same number of rows that the size of the string array.

This is my string array:

String[][] data = {
   {"001", "JOHN ","1001" },
   {"002", "SIBIN", "1002" },
   {"003", "TOM ",   "1003" },
   {"004", "FREEDY", "1004" }
   };

I want to display it in a Listview like

ID    NAME   VACANCY ID
001   JOHN    1001
002   SIBIN   1002
003   TOM     1003
004   FREEDY  1004

Also when I click a list-view item, it redirect to another page with the listview id

How is this possible? I am new in the android development, I know only the basics, and I only know how to create listview.

5
  • what have you already tried? Commented Feb 19, 2013 at 9:22
  • Hi Rajitha, i tried to create a listview with 3 column, but i dont know how to add dynamically data to listview from the string array Commented Feb 19, 2013 at 9:25
  • can you post your code? you will have to create a custom adapter for the ListView. Commented Feb 19, 2013 at 9:27
  • @Sibinfrancis Go through the links provided in below...i am sure u answer is there only...No can write a code, base on your requirement, u have to crack this out from the below link. Commented Feb 19, 2013 at 9:28
  • Thanx Rajitha...thatis the right way.. but why people downvote my question?? iam new in android.. iam not an expert.. Commented Feb 19, 2013 at 9:30

1 Answer 1

5

for that you need a customize list view first you should add a listview in your main.xml(just an eg) file then create a class like this

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
      private final Context context;
      private final String[] values;
      DataHelper dh;

      public MySimpleArrayAdapter(Context context, int textViewResourceId, String[] values) {
        super(context, textViewResourceId, values);
        this.context = context;
        this.values = values;

        dh=new DataHelper(getApplicationContext());
      }

      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_name, parent, false);
       textView = (TextView) rowView.findViewById(R.id.textname);

        textView.setText(values[position]);
        // Change the icon for Windows and iPhone
        textView.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) 
               {
                   Toast.makeText(this,""+values[position],10000).show();
               }
               });


        return rowView;
} 

R.layout.list_name this will be the new xml file which will load the contents to the list view

and the the final step just in your on create method do this

con = (ListView) findViewById(R.id.main_listView); 
 MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(MainActivity.this,  R.id.main_listView ,data);// data is String array valu to be added in list view
    //setting the adapter
    con.setAdapter(adapter);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.