: 여기
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;
}
}
출력의 스크린 샷에 대한 링크입니다
// try this way
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Menu"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1"/>
<Button
android:id="@+id/basketBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/basket" />
<Button
android:id="@+id/setupBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/slaveSetupBtn" />
</LinearLayout>
bi 어댑터에 대해'getView()'메소드를 구현 한 곳을 알려줄 수 있습니까? 귀하의 목록보기에 nded? – rperryng
@Rperryng 뷰와 어댑터를 설정하는 활동을 추가했습니다. –