我在这里有这个列表视图。我已经显示了某些金额,现在我希望带有 - 的金额为红色,带有 + 的金额为绿色。
这是我的代码-:
public class Myperwallet extends ListActivity {
ImageView upload,more,logout,send,history;
String userpin;
TextView fname,lname,cur,bal,pin;
String firstname,lastname,curr,balance,pin1,deb;
static final String baseURL = "http://192.168.0.2:10095/androidxml/permywallet.php?usenam=";
static final String KEY_ITEM = "item";
static final String KEY_DATE = "date";
static final String KEY_DEB = "debit";
static final String KEY_TID = "transactionID";
static final String KEY_AMO = "amount";
static final String KEY_CAT = "category";
static final String KEY_FNM = "firstname";
static final String KEY_LNM = "lastname";
static final String KEY_PIN = "pin";
static final String KEY_BAL = "balance";
static final String KEY_CUR = "currency";
static final String KEY_FEES = "fees";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myperwallet);
Bundle gotuser= getIntent().getExtras();
userpin= gotuser.getString("username");
more = (ImageView)findViewById(R.id.imageView6);
upload= (ImageView)findViewById(R.id.imageView3);
logout =(ImageView)findViewById(R.id.logout);
send =(ImageView)findViewById(R.id.imageView4);
history =(ImageView)findViewById(R.id.imageView5);
fname = (TextView)findViewById(R.id.textView1);
lname = (TextView)findViewById(R.id.textView2);
cur = (TextView)findViewById(R.id.textView5);
bal = (TextView)findViewById(R.id.textView4);
pin = (TextView)findViewById(R.id.textView6);
history.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String username2 = userpin;
Bundle user1 = new Bundle();
user1.putString("username",username2);
Intent next = new Intent(Myperwallet.this,History.class);
next.putExtras(user1);
startActivity(next);
}
});
more.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String username2 = userpin;
Bundle user1 = new Bundle();
user1.putString("username",username2);
Intent next = new Intent(Myperwallet.this,More.class);
next.putExtras(user1);
startActivity(next);
}
});
upload.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String username2 = userpin;
Bundle user1 = new Bundle();
user1.putString("username",username2);
Intent next = new Intent(Myperwallet.this,Uploadfund.class);
next.putExtras(user1);
startActivity(next);
}
});
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String username2 = userpin;
Bundle user1 = new Bundle();
user1.putString("username",username2);
Intent i = new Intent(Myperwallet.this,Sendfund.class);
i.putExtras(user1);
startActivity(i);
}
});
logout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
AlertDialog alertDialog = new AlertDialog.Builder(Myperwallet.this).create();
alertDialog.setTitle("FastCashier:");
alertDialog.setMessage("Are you sure you want to exit?");
alertDialog.setButton( Dialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent logout = new Intent(Myperwallet.this,Login.class);
startActivity(logout);
}
});
alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
});
StringBuilder URL= new StringBuilder(baseURL);
URL.append(userpin);
String fullUrl =URL.toString();
Log.i("log_tag", "new url " + fullUrl);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
inboxParser parser = new inboxParser();
String xml = parser.getXmlFromUrl(fullUrl);
Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
firstname = parser.getValue(e, KEY_FNM);
lastname = parser.getValue(e, KEY_LNM);
curr = parser.getValue(e, KEY_CUR);
balance= parser.getValue(e, KEY_BAL);
pin1= parser.getValue(e, KEY_PIN);
deb = parser.getValue(e, KEY_DEB);
map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
map.put(KEY_DEB, parser.getValue(e, KEY_DEB));
map.put(KEY_TID, parser.getValue(e, KEY_TID));
map.put(KEY_AMO, parser.getValue(e, KEY_AMO));
map.put(KEY_CAT, parser.getValue(e, KEY_CAT));
map.put(KEY_FNM, parser.getValue(e, KEY_FNM));
map.put(KEY_LNM, parser.getValue(e, KEY_LNM));
map.put(KEY_CUR, parser.getValue(e, KEY_CUR));
map.put(KEY_PIN, parser.getValue(e, KEY_PIN));
map.put(KEY_BAL, parser.getValue(e, KEY_BAL));
map.put(KEY_FEES, parser.getValue(e, KEY_FEES));
menuItems.add(map);
}
fname.setText(firstname);
lname.setText(lastname);
cur.setText(curr);
bal.setText(balance);
pin.setText(pin1);
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.recentlist,
new String[] { KEY_CAT, KEY_DATE, KEY_TID, KEY_AMO, KEY_DEB,KEY_CUR,KEY_BAL,KEY_FEES}, new int[] {
R.id.textView1,R.id.textView2, R.id.textView3, R.id.textView4,R.id.textView5,R.id.textView7,R.id.textView6,R.id.textView8});
setListAdapter(adapter);
}
}
xml文件的代码-:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/mywallet" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/wallet_ic_hover"
android:tileMode="repeat" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/imageView2"
android:background="@drawable/upload_ic"
android:tileMode="repeat" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/imageView3"
android:background="@drawable/send_ic"
android:tileMode="repeat" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/imageView4"
android:background="@drawable/history1"
android:tileMode="repeat" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/imageView5"
android:background="@drawable/more"
android:tileMode="repeat" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:layout_marginTop="84dp"
android:background="@drawable/recent_activity"
android:tileMode="repeat" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView7" >
</ListView>
<ImageView
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:src="@drawable/logout" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView3"
android:layout_below="@+id/imageView1"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textSize="9pt"
android:gravity="right"
android:textStyle="bold"
android:textColor="#2e508b"
android:text="TextV" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:layout_marginLeft="10dp"
android:textSize="9pt"
android:gravity="left"
android:textStyle="bold"
android:textColor="#2e508b"
android:text="Text" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="16dp"
android:textStyle="bold"
android:textColor="#2e508b"
android:textSize="8pt"
android:layout_marginLeft="5dp"
android:text="Balance:" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:layout_marginLeft="5dp"
android:textColor="#2e508b"
android:textSize="8pt"
android:text="TextView" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_toRightOf="@+id/textView4"
android:layout_marginLeft="5dp"
android:textColor="#2e508b"
android:textSize="8pt"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView5"
android:layout_alignBottom="@+id/textView5"
android:layout_alignParentRight="true"
android:textColor="#2e508b"
android:textSize="8pt"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView6"
android:layout_alignBottom="@+id/textView6"
android:layout_toLeftOf="@+id/textView6"
android:textStyle="bold"
android:textColor="#2e508b"
android:layout_marginRight="5dp"
android:textSize="8pt"
android:text="Pin:" />
</RelativeLayout>
这是列表视图的 xml 布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Medium Text"
android:layout_marginLeft="5dp"
android:textStyle="bold"
android:textColor="#2E508B"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:textColor="#2E508B"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="10dp"
android:textColor="#2E508B"
android:layout_marginLeft="5dp"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentRight="true"
android:text="Medium Text"
android:textColor="#2e508b"
android:textStyle="bold"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_toLeftOf="@+id/textView4"
android:text="T"
android:textStyle="bold"
android:textColor="#2e508b"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView4"
android:layout_marginTop="19dp"
android:layout_toRightOf="@+id/textView1"
android:text="TextView"
android:visibility="gone"
/>
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_centerHorizontal="true"
android:text="TextView"
android:visibility="gone"
/>
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="TextView"
android:visibility="gone"
/>
</RelativeLayout>