jeudi 11 juin 2015

How to set a different textview for different columns

I have a java class that is retriving two columns from a database in android sqllite. Is it possible to set different textviews layout properties to the two columns? If yes, I would wish to know the way to go.

This is what i have done so far.

my textview layout properties

<----Main Title---->
<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textSize="14sp"
android:textStyle="bold" />

<!-- Subtitle-->
<TextView
android:id="@+id/secondLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/firstLine"
android:layout_below="@id/firstLine"
android:textSize="12sp"
 />

This is the method for quering our the data from the database

    /**
     * DISPLAY RESULTS
     */

    //Create Cursor object to read notification from the table
    Cursor c = db.rawQuery("SELECT ID,NOTIFICATIONS FROM notices order by ID desc", null);

    //If Cursor is valid
    if (c != null ) {
        Toast.makeText(Notification.this, "Query is valid", Toast.LENGTH_LONG).show();

        //Move cursor to first row
        if  (c.moveToFirst()) {
            do {

                String Name = c.getString(c.getColumnIndex("NOTIFICATIONS"));

               int Ids = c.getInt(c.getColumnIndex("ID"));

                //Add the notification to Arraylist 'results'
                results.add(Name);


            }while (c.moveToNext()); //Move to next row
        }
    }


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    R.layout.notification_textview,R.id.firstLine, results);


    // Assign adapter to ListView
    listView.setAdapter(adapter); 

In this case, I would want the firstLine textview properties be set for the Name column and the secondLine textview properties be set for the Ids colums.

Thanks for helping.

Aucun commentaire:

Enregistrer un commentaire