Friday, March 28, 2014

android custom Adapter in getView method does not perform


android custom Adapter in getView method does not perform what are the reasons? ?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
How not to execute a method? What's log output or log logs do not? It asked.
Reply:
There is no value in the display list 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 ().);

/ / Delete button
Profile menuiv_delete = (ImageButton) convertView
. FindViewById (R.id.ibtn_delete);

}}
Reply:
Ah return view. . .
Reply:
To first call super.getView (....), and then reload
Reply:
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
*
* Adapter
Profile menu*
* /
public class PictureViewConciseMyOrderAdapter extends BaseAdapter {
private Context context;
private LinearLayout linearLayout;
private LayoutInflater inflater;
private List nameAndprice = new ArrayList ();
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);

/ / Delete button
Profile menuiv_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 ()) ;/ / delete data
temporary table from the databasedb.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 can load data is the data come in effect does not show up
Reply:
OnCreate () inside the loaded data
listViewconciseorder_listview = (ListView) findViewById (R.id.myorder_listview);
concise_MyOrderAdapter = new PictureViewConciseMyOrderAdapter (this);
/ / Concise_MyOrderAdapter.notifyDataSetChanged ();
conciseorder_listview.setAdapter (concise_MyOrderAdapter);
Reply:
How no attention to me? ?
Reply:
Saw ten minutes, tired. Readability of the code can be imagined.

Looked for a long time do not understand your handler is doing? The absence of a transmission request that it does not perform ah.

Generally understand your thinking, is receiving data handler, 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? ?
Reply:
This mean! ! Activity in manufacturing in several false data can be loaded into the listview, so why not do it? ?
Reply:
reference to the 8th floor sunmable reply:
watched ten minutes, tired. Readability of the code can be imagined.

Looked for a long time do not understand your handler is doing? The absence of a transmission request that it does not perform ah.

Generally understand your thinking, is receiving data handler, 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? ?



This mean! ! Activity in manufacturing in several false data can be loaded into the listview, so why not do it? ?
Reply:
Then you need to add the data before setting the adapter, if there is no view, then it certainly did not view
Reply:
If you say no, then you certainly view the adapter is set to increase after the data. This is just my guess ......
Reply:
Encountered the same problem, seek the truth!
Reply:
The landlord did not solve the problem? Give a reply!
Reply:
reference to the 13th floor zk786957037 reply:
encountered the same problem, seek the truth!

I have a handler problems
Reply:
listView draw in the beginning, the system first calls the getCount () function, according to the length of his return listView worth, and then according to the length of the call getView () to draw each line individually. If your getCount () return value is 0, then the list will not show the same return 1, it displays only one line. When the system displays a list, the first instance of an adapter (adapter here will instantiate custom). When done manually fit, you must manually map data, which need to override getView () method. System when drawing each line of the list will call this method. getView () has three parameters, position said it will display the first few lines, covertView from the layout of the document to the inflate layout. We use LayoutInflater method to extract the files into a defined item.xml View instance to display. Xml file and then instantiate each component (simple findViewById () method). This makes it possible to map data to the various components of the. However, in response to the button click event, you need to click on it to add a listener, so you can capture the click event. Thus a custom listView complete, now let's go back and re-examine the process. To draw ListView system, he first obtains the length of this list to be drawn, and then start drawing the first line, how to draw it? Call getView () function. In this function, which first obtains a View (actually a ViewGroup), then each component instance and set the display of. Well, this line has been drawn up. It then draws the next line, until you have painted so far.


Estimate your getCount () return value is 0



Reply:
reference to the 16th floor kakaxige reply:
listView draw in the beginning, the system first calls the getCount () function, according to his worth to return listView length Then according to the length of the call getView () to draw each line individually. If your getCount () return value is 0, then the list will not show the same return 1, it displays only one line. When the system displays a list, the first instance of an adapter (adapter here will instantiate custom). When done manually fit, you must manually map data, which need to override getView () method. System when drawing each line of the list will call this method. getView () has three parameters, position said it will display the first few lines, covertView from the layout of the document to the inflate layout. We use LayoutInflater method to extract the files into a defined item.xml View instance to display. Xml file and then instantiate each component (simple findViewById () method). This makes it possible to map data to the various components of the. However, in response to the button click event, you need to click on it to add a listener, so you can capture the click event. Thus a custom listView complete, now let's go back and re-examine the process. To draw ListView system, he first obtains the length of this list to be drawn, and then start drawing the first line, how to draw it? Call getView () function. In this function, which first obtains a View (actually a ViewGroup), then each component instance and set the display of. Well, this line has been drawn up. It then draws the next line, until you have painted so far.


Estimate your getCount () return value is 0


I encountered this problem really is such a reason.
Reply:
Gridview I have encountered this problem, really feel very speechless! Metamorphosis
Reply:
Look at the layout of the problem, focusing on look gridview
Reply:
references, 4th Floor kechanghe0705 reply:
to first call super.getView (....), and then reload
Shabi The answer you can answer them
Reply:
Encountered the same problem, the data getCount () to get a 3, but did not execute the method getView
Reply:

No comments:

Post a Comment