------ Solution ---------------------------------------- ----
how one does not perform law? What is the log output or log logs do not? It asked.
------ For reference only -------------------------------------- -
not show list also has a value that is not displayed
public View getView (int position, View convertView, ViewGroup viewGroup) {
inflater = LayoutInflater.from (context);
if (convertView == null) {
convertView = inflater.inflate (R.layout.myorder_listview, null);
/ / About menu dish
TextView txt_mealName = (TextView) convertView
. findViewById (R.id.txt_mealname);
System.out.println ("gmajjjkkkklg"
+ nameAndprice.get (position). getName ());
txt_mealName.setText (nameAndprice.get (position). getName ());
/ / About menu Delete button
iv_delete = (ImageButton) convertView
. findViewById (R.id.ibtn_delete);
}}
------ For reference only -------------------------------- -------
ah return view. . .
------ For reference only -------------------------------------- -
should first call super.getView (....), and then reload
------ For reference only ------------------ ---------------------
package com.teego.adapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import com.teego.activity.PictureViewActivity;
import com.teego.activity.R;
import com.teego.db.DBHelperColumn;
import com.teego.db.DataBaseHelper;
import com.teego.db.SqliteHelperUtil;
import com.teego.entity.Vegetable;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
/ **
* @ author wangtao
*
* Profile menu Adapter
*
* /
public class PictureViewConciseMyOrderAdapter extends BaseAdapter {
private Context context;
private LinearLayout linearLayout;
private LayoutInflater inflater;
private List
private Vegetable vv;
private SqliteHelperUtil db;
private ImageButton iv_delete;
private TextView txt_mealName;
private Vegetable vt = new Vegetable ();
private LayoutInflater layoutInflater;
private static PictureViewConciseMyOrderAdapter instance = null;
private PictureViewActivity pv = new PictureViewActivity ();
public Handler handler = new Handler () {
public void handleMessage (Message msg) {
super.handleMessage (msg);
Bundle b = msg.getData ();
Vegetable vv = new Vegetable ();
vv.setName (b.getString ("mealname"));
vv.setPrice (b.getInt ("mealprice"));
vv.setId (b.getInt ("id"));
Log.i ("bundle data inside 11111", b.get ("mealname") + "");
Log.i ("mealname data 111111", b.getInt ("mealprice") + "");
Log.i ("mealprice data 11111", b.getInt ("id") + "");
addMealName (vv);
notifyDataSetChanged ();
};
};
public PictureViewConciseMyOrderAdapter () {
}
public PictureViewConciseMyOrderAdapter (Context context) {
this.context = context;
layoutInflater = (LayoutInflater) this.context
. getSystemService (Context.LAYOUT_INFLATER_SERVICE);
}
public static PictureViewConciseMyOrderAdapter getInstance () {
if (instance == null) {
instance = new PictureViewConciseMyOrderAdapter ();
}
return instance;
}
@ Override
public int getCount () {
return nameAndprice.size ();
}
@ Override
public Object getItem (int position) {
return nameAndprice.get (position);
}
@ Override
public long getItemId (int position) {
return position;
}
@ Override
public View getView (int position, View convertView, ViewGroup viewGroup) {
linearLayout = (LinearLayout) layoutInflater.inflate (
R.layout.myorder_listview, null);
/ / inflater = LayoutInflater.from (context);
/ / if (convertView == null) {
/ / convertView = inflater.inflate (R.layout.myorder_listview, null);
/ / About menu dish
txt_mealName = (TextView) linearLayout.findViewById (R.id.txt_mealname);
/ / About menu Delete button
iv_delete = (ImageButton) linearLayout.findViewById (R.id.ibtn_delete);
/ /}
vt = nameAndprice.get (position);
System.out.println ("gmajjjkkkklg"
+ nameAndprice.get (position). getName ());
txt_mealName.setText (vt.getName ());
iv_delete.setTag (position);
Log.i ("tag: Position", position + "");
iv_delete.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View view) {
int tag = (Integer) view.getTag ();
/ / vv = new Vegetable ();
vv = nameAndprice.get (tag);
nameAndprice.remove (nameAndprice.get (tag));
notifyDataSetChanged ();
System.out.println ("temporary database ID" + vv.getId ());
db = new SqliteHelperUtil (context);
db.deleteDataFromTable (vv.getId ()) ;/ / removed from the database data in the temporary table
db.close ();
}
});
return linearLayout;
}
/ / delete the name of the dish
public void deleteMealItem (int index) {
nameAndprice.remove (index);
notifyDataSetChanged ();
}
public void addMealName (Vegetable vt_name) {
vv = new Vegetable ();
vv.setName (vt_name.getName ());
vv.setPrice (vt_name.getPrice ());
vv.setId (vt_name.getId ());
nameAndprice.add (vv);
Log.i ("name111", vt_name.getName ());
Log.i ("name111", vt_name.getPrice () + "");
Log.i ("name111", nameAndprice.size () + "");
this.notifyDataSetChanged ();
System.out.println ("getCount ()" + getCount ());
}
}
addMealName (Vegetable vt_name) this method is that the data can be loaded incoming data does not show up effect
------ For reference only ------- --------------------------------
OnCreate () to load the data inside the listView
conciseorder_listview = (ListView) findViewById (R.id.myorder_listview);
concise_MyOrderAdapter = new PictureViewConciseMyOrderAdapter (this);
/ / concise_MyOrderAdapter.notifyDataSetChanged ();
conciseorder_listview.setAdapter (concise_MyOrderAdapter);
------ For reference only --------------------------- ------------
how no attention to me? ?
------ For reference only -------------------------------------- -
watched ten minutes, tired. Readability of the code can be imagined.
looked for a long time do not understand your handler is doing? No transmission request in the case that it does not run ah.
generally understand your thinking, that handler to receive data, then addMealName () so nameAndprice in this list have the data.
Is that right?
but I do not understand is the msg handler is how come? ?
------ For reference only -------------------------------------- -
mean it! ! Activity in manufacturing in several false data can be loaded into listview, so why not do it? ?
------ For reference only -------------------------------------- -
mean it! ! Activity in manufacturing in several false data can be loaded into listview, so why not do it? ?
------ For reference only -------------------------------------- -
then you need to add the data before setting the adapter, if no view, then it is certainly not view
------ For reference only --------------- ------------------------
If there is no view, then you must be set up before the increase in the data adapter. This is just my guess ......
------ For reference only --------------------------- ------------
encountered the same problem, seeking the truth!
------ For reference only -------------------------------------- -
landlord did not solve the problem? Give a reply!
------ For reference only -------------------------------------- -
I have a handler problems
------ For reference only ----------------------- ----------------
listView when you start drawing, the system first calls getCount () function, according to his return to the listView worth the length, and then according to the length of the calling getView () draw each line individually. If your getCount () return value is 0, then the list will not show the same return 1, it only shows one line. The system displays a list, the first instance of an adapter (this will instantiate a custom adapter). When done manually fit, you must manually map data, which need to override getView () method. System each line is drawn when the list will call this method. getView () has three parameters, position said it will display the first few lines, covertView is to inflate the layout file in the layout. The method we use LayoutInflater defined item.xml will extract the files into a View instance to display. Xml file and then instantiate the various components (simple findViewById () method). This allows the data corresponding to each component on the. However, in response to the button click event, you need to add it click listener, so you can capture the click event. Thus a custom listView is complete, now let's go back and re-examine the process. System to draw ListView, he first get to draw the length of this list, and then start drawing the first line, how draw it? Call getView () function. In this function, which first obtain a View (actually a ViewGroup), and then set up each component instance and display it. Well, the finished drawing the line. That re-draw the next line until painted last.
guess you getCount () return value is 0
------ For reference only ---------------------------------- -----
I encountered this problem really is such a cause.
------ For reference only -------------------------------------- -
my gridview also encountered this problem, really feel speechless! , Perverted
------ For reference only ------------------------------------ ---
look at the layout of the problem, look at the focus gridview
没有评论:
发表评论