lundi 6 juillet 2015

My data in a string don't appear as a list view

iam beginner in android , i made code to get data from sqlite database and put it in a string , and thin i make loop to put strings in array . i need to put data from this array string ii into a list view , this is my code , my data is stored at array string (ii) but when i run my app it forced to stop

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    cnxt = this;
    b1 = (Button) findViewById(R.id.get_cust_btn);
    lv1 = (ListView) findViewById(R.id.listView);

            DOP =  DatabaseHandler.getInstance(cnxt);
            Cursor CR2 = DOP.getCustomers(DOP);
            CR2.moveToFirst();
            String ii[] = new String[4];

            Intent i = getIntent();
            Bundle b = i.getBundleExtra("cust_info");
            int user_id = b.getInt("user_id");
            int cust_user_id;
            String Status ;
            int cust_code ;
            int count = 0;
            ListView listView = (ListView) findViewById(R.id.listView);


           do{
               cust_user_id = CR2.getInt(CR2.getColumnIndex("User_id"));
               Status = CR2.getString(CR2.getColumnIndex("Status"));
               cust_code = CR2.getInt(CR2.getColumnIndex("customer_code"));
               String cust_name = CR2.getString(CR2.getColumnIndex("Customer_name"));

               if (user_id == cust_user_id){
                   ii[count]= cust_name;

                Toast.makeText(getBaseContext(), "customer is " + cust_name, Toast.LENGTH_LONG).show();
                   count++;

            }}while (CR2.moveToNext());

           ArrayAdapter<String> itemsAdapter =
                    new ArrayAdapter<String>(SecondActivity.this, android.R.layout.simple_list_item_1, ii);

            listView.setAdapter(itemsAdapter);





}

Aucun commentaire:

Enregistrer un commentaire