P
ping87
Neues Mitglied
- 0
Hallo.
Habe folgendes Problem.
Ich konstruiere eine ListActivity in der halt Items angezeigt werden. Wenn der User auf ein Item klickt sollte dieses sich öffnen und details anzeigen.
Jede Reihe in der ListActivity besteht aus zwei nebeneinander stehenden textviews die immer sichtbar sind. Und darunter ein Tablelayout, welches dynamisch mit den detaildaten gefüllt wird. Zunächst ist dieses TableLayut auf unsichtbar gesetzt (setVisibility()). Soweit so gut.
Nun soll dieser TableLayout sichtbar werden wenn der user eben auf einen eintrag in der ListActivity klickt. Also mache ich in der onItemClicked() methode der ListActivity wieder ein setVisibility() diesmal auf true. Aber leider wird des TableLayout nicht angezeigt... :/ ich denke da muss ich irgendwie die ListView refreshen oder so... kann mir da jemand weiterhelfen??? hier mal der enstprechende code:
und hier noch die beiden dazugehörigen XML files:
show_purchases_row.xml
show_purchases.xml:
Habe folgendes Problem.
Ich konstruiere eine ListActivity in der halt Items angezeigt werden. Wenn der User auf ein Item klickt sollte dieses sich öffnen und details anzeigen.
Jede Reihe in der ListActivity besteht aus zwei nebeneinander stehenden textviews die immer sichtbar sind. Und darunter ein Tablelayout, welches dynamisch mit den detaildaten gefüllt wird. Zunächst ist dieses TableLayut auf unsichtbar gesetzt (setVisibility()). Soweit so gut.
Nun soll dieser TableLayout sichtbar werden wenn der user eben auf einen eintrag in der ListActivity klickt. Also mache ich in der onItemClicked() methode der ListActivity wieder ein setVisibility() diesmal auf true. Aber leider wird des TableLayout nicht angezeigt... :/ ich denke da muss ich irgendwie die ListView refreshen oder so... kann mir da jemand weiterhelfen??? hier mal der enstprechende code:
PHP:
package com.berndwarmuth.client.shopper.activities;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.berndwarmuth.client.shopper.Item;
import com.berndwarmuth.client.shopper.Purchase;
import com.berndwarmuth.client.shopper.R;
public class ShowPurchasesActivity extends ListActivity {
private ShowItemsArrayAdapter siaa;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.show_purchases);
siaa = new ShowItemsArrayAdapter(this, new ArrayList<Purchase>());
//...
//...
setListAdapter(siaa);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
TableLayout tl = (TableLayout) (siaa.getView(position, null, null))
.findViewById(R.id.purchase_details);
tl.setVisibility(View.VISIBLE); //GEHT NIIIIIIT!
}
// CUSTOM ARRAY ADAPTER
public class ShowItemsArrayAdapter extends ArrayAdapter<Purchase> {
private Activity context;
private List<Purchase> purchases;
public ShowItemsArrayAdapter(Activity context, List<Purchase> purchases) {
super(context, R.layout.my_items_item_row, purchases);
this.context = context;
this.purchases = purchases;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.show_purchases_row, null,
true);
// GETTING VIEWS
TextView txtItemLabel = (TextView) rowView
.findViewById(R.id.lbl_purchase_owner);
TextView txtItemPrice = (TextView) rowView
.findViewById(R.id.lbl_purchase_date);
txtItemLabel.setText(purchases.get(position).getOwner());
txtItemPrice.setText(purchases.get(position).getDate());
// HIDE TABLELAYOUT (detailed informations of one purchase)
TableLayout tl = (TableLayout) rowView
.findViewById(R.id.purchase_details);
// GETTING ITEMS
ArrayList<Item> items = (ArrayList<Item>) purchases.get(position)
.getItems();
// ITERATE OVER ITEMS & CREATE TABLE ROWS
for (Item i : items) {
/* Create a new row to be added. */
TableRow tr = new TableRow(ShowPurchasesActivity.this);
TextView tv = new TextView(ShowPurchasesActivity.this);
tv.setText(i.getLabel());
tv.setPadding(10, 0, 0, 0);
TextView tv2 = new TextView(ShowPurchasesActivity.this);
tv2.setText(i.getPrice().toString());
tv2.setGravity(Gravity.RIGHT);
tr.addView(tv);
tr.addView(tv2);
/* Add row to TableLayout. */
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
tl.setVisibility(View.GONE);
return rowView;
}
@Override
public void add(Purchase object) {
super.add(object);
}
@Override
public Purchase getItem(int position) {
return super.getItem(position);
}
public List<Purchase> getItems() {
return this.purchases;
}
}
}
und hier noch die beiden dazugehörigen XML files:
show_purchases_row.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#999999" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:text="@+id/txt_item" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lbl_purchase_owner"
android:textSize="30px"></TextView>
<TextView android:layout_alignParentRight="true"
android:textSize="30px" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lbl_purchase_date"
android:layout_toLeftOf="@id/lbl_purchase_owner">
</TextView>
</RelativeLayout>
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#999999" />
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1" android:id="@+id/purchase_details">
</TableLayout>
</LinearLayout>
Code:
<?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="fill_parent" android:paddingLeft="8dp"
android:paddingRight="8dp">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Purchases"
android:textSize="30px"
android:gravity="center_horizontal" android:layout_marginBottom="20dp"/>
<ListView android:id="@id/android:list" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="1"
android:drawSelectorOnTop="false" />
<TextView android:id="@id/android:empty" android:layout_width="match_parent"
android:layout_height="match_parent" android:text="No Purchases"
android:gravity="center_horizontal"/>
</LinearLayout>
Zuletzt bearbeitet: