I wrote an android app in Eclipse and I show some information to user from my database with using xml.Here is my xml and related code part.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="get info from db"
android:id="@+id/dbView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TextView>
</LinearLayout>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
TextView history=(TextView) findViewById(R.id.dbView);
Database myDB=new Database(this);
myDB.open();
String data=myDB.getData();
myDB.closeDB();
history.setText(data);
}
public String getData() {
String attributes[] = new String[]{Key_ID,Key_Name,Key_Cost,Key_Type,Key_Date};
Cursor cursor=myDatabase.query(DB_TABLE,attributes,null,null,null,null,Key_Name+ " DESC ");
String result="";
int Row = cursor.getColumnIndex(Key_ID);
int Nameof = cursor.getColumnIndex(Key_Name);
int Costof = cursor.getColumnIndex(Key_Cost);
int Typeof = cursor.getColumnIndex(Key_Type);
int Dateof = cursor.getColumnIndex(Key_Date);
for (cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
result = result + cursor.getString(Row)+" "+cursor.getString(Nameof)+" "+cursor.getString(Costof)+" "+cursor.getString(Typeof)+" "+cursor.getString(Dateof)+"\n" ;
}
return result;
}
I tried to minimize the density of code as much as possible in this example. So if you need extra info about code I can add it. What I want to accomplish is following. When I write tuples one by one in each row I want to say that if Typeof="x" then write this tuple with green color else write this tuple with red color. How can I do that?