-1
我有一个列表视图,当它被设置为顶视图时显示其黑色文本,但是当嵌套在另一个布局如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" >
<Button
android:id="@+id/purchaseBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/list_view"
android:layout_centerHorizontal="true"
android:layout_marginBottom="78dp"
android:text="@string/purchase" />
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header" >
</ListView>
<Button
android:id="@+id/menuReturnBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/purchaseBtn"
android:layout_centerHorizontal="true"
android:text="@string/productMenu" />
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/checkoutHeader"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
这里是设置列表视图的活动:
public class Checkout extends Activity implements OnItemClickListener {
private MasterDatabaseAdapter db;
private Button checkoutBtn;
private Button menuReturnBtn;
private ListView list;
private List<String> orderArray;
private StringTokenizer tokens;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkout_orders);
// initiate database
db = new MasterDatabaseAdapter(getApplicationContext());
checkoutBtn = (Button) findViewById(R.id.checkoutBtn);
menuReturnBtn = (Button) findViewById(R.id.menuReturnBtn);
list = (ListView) findViewById(R.id.list_view);
// setup order list
orderArray = new ArrayList<String>();
getReceipt(); // fills up orderArray with receipt output
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, orderArray);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
// navigate to product menu
menuReturnBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
db.closeDB();
Intent launchMenu = new Intent(Checkout.this,
ProductMenu.class);
startActivity(launchMenu);
}
});
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String code;
String viewString = ((TextView) view).getText().toString();
tokens = new StringTokenizer(viewString);
// iterate through list view text
tokens.nextToken(); // skip code label
code = tokens.nextToken(); // product code value
// close database before navigating
db.closeDB();
Intent launchOrderItem = new Intent(Checkout.this,
OrderItem.class);
launchOrderItem.putExtra("code", code); // pass code to another activity
startActivity(launchOrderItem); // launch new activity
}
// displays receipt of ordered items
public List<String> getReceipt(){
String temp = "";
Product item = null;
// fetch list of products
List<Product> products = db.getAllProducts();
Log.i("Checkout", "fetched all products + count=" + products.size());
// get iterator for product list
Iterator<Product> iterator = products.iterator();
while (iterator.hasNext()){
item = iterator.next();
// format receipt display before outputting
temp = "CODE: " +item.getCode() + " @R"+item.getPrice() +" x"+db.countOrders(item.getCode());
Log.i("Checkout", temp);
orderArray.add(temp);
}
Log.i("Checkout", "Size of orderArray: "+orderArray.size());
return orderArray;
}
}
这里是一个输出的截图链接: https://drive.google.com/file/d/0BwxIRxqhBpk3amlELVJ4SHZndWs/edit?usp=sharing
你能告诉我们你在哪里实现了适配器biView的getView()方法吗? nded到你的列表视图? – rperryng
@Rperryng我已经添加了设置视图和适配器的活动。 –