I already saw a bunch of questions but i didn't found an solution! What im doing wrong? Why getView is never called?!
Here`s my adapter:
public class ConteudoAdapter<T extends IProgramacao> extends BaseAdapter {
private Context context;
private List<T> list;
private int resourceId;
public ConteudoAdapter(Context context, int resourceId, List<T> list){
this.context = context;
this.list = list;
this.resourceId = resourceId;
}
#Override
public int getCount() {
Log.v("test", "Returning count " + (this.list.size() != 0 ? this.list.size() : 0));
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
View row = view;
ViewHolder holder = null;
T entidade = list.get(position);
if(row == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(resourceId, parent, false);
holder = new ViewHolder();
holder.tvTitle = (TextView) row.findViewById(R.id.tvTitle);
holder.tvTitle.setText(entidade.getTitulo());
holder.tvConteudo = (TextView) row.findViewById(R.id.tvConteudo);
holder.tvConteudo.setText(entidade.getChamada());
row.setTag(holder);
}
// holder.ivImg = (ImageView) layout.findViewById(R.id.nivImg);
// holder.ivImg.setImageResource(entidade.);
// IMAGE VIEW
// holder.ivImg.setVisibility(View.VISIBLE);
// il.get(list.get(position).getUrlImage(), il.getImageListener(holder.ivImg, R.drawable.load, R.drawable.error));
//tvTitle.setText(entidade.getTitulo());
return view;
}
public static class ViewHolder{
//public NetworkImageView nivImg;
//public ImageView ivImg;
public TextView tvTitle;
public TextView tvConteudo;
}
}
Here`s how i call my adapter (inside an asynctask because im getting values from web (JSON):
public class CategoriaEventoFragment extends SherlockFragment {
private View rootView;
private EventoBO evento;
private ListView lv;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
rootView = (View) inflater.inflate(R.layout.categoria, container, false);
CarregaDadosCategoriaEventoCaller carregaDadosCategoriaEventoCaller = new CarregaDadosCategoriaEventoCaller();
carregaDadosCategoriaEventoCaller.execute((Void[]) null);
return super.onCreateView(inflater, container, savedInstanceState);
}
public class CarregaDadosCategoriaEventoCaller extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
evento = new EventoBO("http://urlhere");
evento.popularListaImagemChamada("http://urlhere");
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
lv = (ListView) rootView.findViewById(R.id.listViewCategoria);
lv.setAdapter(new ConteudoAdapter<Evento>(rootView.getContext(), R.layout.item, evento.getLista()));
}
}
}
}
XML FILES:
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/home_bg_branco"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tvConteudo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
categoria.xml
<?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" >
<ListView
android:id="#+id/listViewCategoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/home_bg_branco" >
</ListView>
</LinearLayout>
My LogCat Returns this for my verbose test:
09-02 17:13:27.322: V/test(24961): Returning count 5
09-02 17:13:27.322: V/test(24961): Returning count 5
Thanks in advance!!!
In onCreateView() you should be returning the rootView instead of the super.
Related
I would like to create a simple populated GridView using BaseAdapter but I keep getting empty list - application runs but there are no Views displayed.
Below are all files are use for this task:
Main:
String[] items = {"Some", "items", "to", "display"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView grid = (GridView)findViewById(R.id.grid);
final TextView text = (TextView)findViewById(R.id.text);
MyAdapter adapter = new MyAdapter(getApplicationContext(), items);
grid.setAdapter(adapter);
MyAdapter:
LayoutInflater inflater;
Context context;
String[] myData;
public MyAdapter(Context context, String[] myData) {
this.context = context;
this.myData = myData;
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int position) {
return myData[position];
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.grid, parent, false);
TextView text = (TextView) convertView.findViewById(R.id.textView);
text.setText(myData[position]);
return convertView;
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.random.MainActivity">
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="40dip"
android:horizontalSpacing="5dip"
android:numColumns="auto_fit"
android:columnWidth="100dip"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</android.support.constraint.ConstraintLayout>
grid.xml:
<?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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</LinearLayout>
I have checked in various sources countles times and I did not manage to find an error in my code. It would be amazing if someone would take a look at it and find a reason for empty activity as the reason is probably obvious.
Your getCount method always return 0. Return the number of elements in your myData array instead.
#Override
public int getCount() {
return myData.length;
}
You can try this my friend
public class MyAdapter extends BaseAdapter {
Context context;
String[] data;
public MyAdapter(Context context, String[] myData) {
this.context = context;
this.data = myData;
}
#Override
public int getCount() {
return data.length;
}
#Override
public Object getItem(int position) {
return data[position];
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.grid, null);
}
TextView text = (TextView) convertView.findViewById(R.id.textView);
text.setText(data[position]);
return convertView;
}
}
A setting picture
How to do that in android?
Before I used to referencescreen but it could'n use icon for each item.
It is a simple Listview. Refer the following code and replace the list_row with the list row design .xml that you want. This should help.
public class ListAdapter extends BaseAdapter {
LayoutInflater inflater;
View row;
public static List<String> list = new ArrayList<String>();
Context context;
class ViewHolder {
ImageView ivShare;
}
public ListAdapter(Context context, List<String> _list) {
this.context = context;
this.list = _list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
ViewHolder holder;
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_row, parent, false);
holder = new ViewHolder();
holder.ivShare = (ImageView) convertView
.findViewById(R.id.iv_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ivShare.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
return convertView;
}
}
Use ListView with CustomAdapter for doing this.
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView lv_applicationlist;
ApplicationListingAdapter adapter;
ArrayList<Integer> app_image=new ArrayList<>();
ArrayList<String> app_name=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv_applicationlist = (ListView) findViewById(R.id.lv_applicationlist);
app_name.add("Camera");
app_name.add("Gallery");
app_name.add("Send");
app_name.add("Share");
app_image.add(R.drawable.ic_menu_camera);
app_image.add(R.drawable.ic_menu_gallery);
app_image.add(R.drawable.ic_menu_send);
app_image.add(R.drawable.ic_menu_share);
adapter = new ApplicationListingAdapter(MainActivity.this, app_name,app_image);
lv_applicationlist.setAdapter(adapter);
}
}
activity_main.xml
<?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">
<ListView
android:id="#+id/lv_applicationlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:listSelector="#android:color/transparent" />
</LinearLayout>
ApplicationListingAdapter.java
public class ApplicationListingAdapter extends BaseAdapter {
private Activity activity;
private static LayoutInflater inflater = null;
ArrayList<String> app_name;
ArrayList<Integer> app_image;
public ApplicationListingAdapter(Activity a, ArrayList<String> application_name, ArrayList<Integer> application_image) {
activity = a;
app_name = application_name;
app_image = application_image;
inflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return app_name.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView tv_appname;
public ImageView iv_appicon;
public Switch mySwitch;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.application_list_row, parent, false);
holder = new ViewHolder();
holder.tv_appname = (TextView) vi.findViewById(R.id.tv_appname);
holder.iv_appicon = (ImageView) vi.findViewById(R.id.iv_appicon);
holder.mySwitch = (Switch) vi.findViewById(R.id.mySwitch);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.tv_appname.setText(app_name.get(position));
holder.iv_appicon.setImageResource(app_image.get(position));
if(app_name.get(position).equals("Send"))
{
holder.mySwitch.setVisibility(View.VISIBLE);
}else{
holder.mySwitch.setVisibility(View.GONE);
}
return vi;
}
}
application_list_row.xml
<?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="wrap_content">
<ImageView
android:id="#+id/iv_appicon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/tv_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="Store App"
android:textSize="20dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:visibility="gone"
android:layout_gravity="center_vertical" />
</LinearLayout>
Output will be look like this :
I am trying to set a text on textView but the object itself is coming null,even though I've defined id attribute in xml.. I'm getting the value to be set in textView but textView object itself is null.
Activity :
public class ItemActivity extends Activity {
ListView lv;
Context context;
ArrayList prgmName;
String dateStr=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported =
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.itemlist);
if(customTitleSupported){
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.item);
}
final TextView myTitleText = (TextView) findViewById(R.id.showRoomTextView);
final TextView textViewStyle = (TextView) findViewById(R.id.textViewStyle);
ArrayList<InvoiceData> invoiceList = (ArrayList<InvoiceData>) getIntent().getSerializableExtra("invoiceList");
for(int i=0;i<invoiceList.size();i++){
if (myTitleText != null) {
myTitleText.setText(invoiceList.get(i).getCompl_Name());
}
String prdNo=invoiceList.get(i).getPrd_No();
if(prdNo!=null) {
System.out.println("no..." + invoiceList.get(i).getPrd_No()+""+textViewStyle);
textViewStyle.setText(invoiceList.get(i).getPrd_No());
}
}
context=this;
lv=(ListView) findViewById(R.id.listView);
lv.setAdapter(new CustomAdapter(this,params.....));
}
and the adapter class is :
public class CustomAdapter extends BaseAdapter{
String [] result;
String [] result1;
String [] result2;
String [] result3;
String [] result4;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(ItemActivity mainActivity, String[] prgmNameList,String[] prgmNameList1,String[] prgmNameList2,String[] prgmNameList3,String[] prgmNameList4) {
// TODO Auto-generated constructor stub
context=mainActivity;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return result.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stubb
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView tv;
TextView tv1;
TextView tv2;
TextView tv3;
TextView tv4;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.tabitem, null);
rowView.setBackgroundColor(Color.parseColor("#F1F1FF"));
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
}
the tabitem xml is
<?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="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="75dp"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textColor="#000000"
android:text="TextView" />
<TextView
android:id="#+id/textViewStyle"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textColor="#000000"
/>
</LinearLayout>
I'm trying to set textViewStyle in activity.
If you want to access the TextView in your list you can't access it in your activity but you can in your adapter :
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// ...
TextView textviewToModify = rowView.findViewById(R.id.textViewStyle);
return rowView;
}
You should also see the ViewHolder pattern to have better perf.
http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Try to use this :
#Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.custom_remarks, null);
textViewStyle= (TextView) view.findViewById(R.id.textViewStyle);
textViewStyle.setText("TextViewStyle");
}
return view;
}
I got a custom ListView, and I put three TextView in the List using a custom List Adapter! How I can to add a CheckBox with each List Item and make each CheckBox checked on list item click?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#7a4b9d"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/calorie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="sdf"
android:textColor="#ffffff" />
<TextView
android:id="#+id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="sdf"
android:textColor="#ffffff" />
<CheckBox
android:id="#+id/chkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
MainActivity
public class Main_Activity extends Fragment implements OnClickListener {
private ListView lv;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.main_activity, null);
ArrayList<SearchResults> searchResults = GetSearchResults();
final ListView lv = (ListView) root.findViewById(R.id.list_two);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setTextFilterEnabled(true);
lv.setAdapter(new MyCustomBaseAdapter(getActivity(), searchResults));
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
boolean result = searchResults.get(position).isSolved();
if (result) {
searchResults.get(position).setSolved(false);
} else {
searchResults.get(position).setSolved(true);
}
Toast.makeText(getActivity(),"You have chosen: " + " " +
fullObject.getPhone(), Toast.LENGTH_SHORT).show();
}
});
return root;
}
private ArrayList<SearchResults> GetSearchResults() {
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
SearchResults sr = new SearchResults();
sr.setName("Apple");
sr.setCalorie("35");
sr.setPrice("5");
results.add(sr);
return results;
}
}
Custom Base Adapter
public class MyCustomBaseAdapter extends BaseAdapter {
private static ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.name);
holder.txtCalorie = (TextView) convertView
.findViewById(R.id.calorie);
holder.txtPrice = (TextView) convertView.findViewById(R.id.price);
holder.chkBox1 = (CheckBox)convertView.findViewById(R.id.chkBox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(searchArrayList.get(position).getName());
holder.txtCalorie.setText(searchArrayList.get(position)
.getCalorie());
holder.txtPrice.setText(searchArrayList.get(position).getPrice());
holder.chkBox1.setChecked(searchArrayList.get(position).isSolved());
return convertView;
}
static class ViewHolder {
CheckBox chkBox1;
TextView txtName;
TextView txtCalorie;
TextView txtPrice;
}
Search Results
public boolean isSolved() {
// TODO Auto-generated method stub
return b;
}
public void setSolved(boolean b) {
// TODO Auto-generated method stub
this.b = b;
}
You will have to define your CheckBox view in custom_row_view.xml file first,
<CheckBox android:id="#+id/chkBox1"
android:layout_width=...
android:layout_height=... />
Then, you wll have to call this reference in your MyCustomBaseAdapter class or in the holder in your case, like
CheckBox chkBox1;
then,
holder.chkBox1 = = (CheckBox)convertView.findViewById(R.id.chkBox1);
You can define a boolean value in your SearchResults class which can take care of chkBox check and use
holder.chkBox1.setChecked(searchArrayList.get(position).isSolved());
Something on these lines and you will be good to go :)
EDIT: Remember to change the value of boolean in searchResult instance on itemClick.
boolean result = searchResults.get(position).isSolved();
if (result) {
searchResults.get(position).setSolved(false);
} else {
searchResults.get(position).setSolved(true);
}
lv.getAdapter().notifyDataSetChanged();
I have written following to show my data into grid view. This is the procedure of my code.
In onCreate()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_newslist);
// Initializing NewsAdapter in order to loading the list of NEWS items
newsAdapter = new NewsAdapter(this);
// Initializing grid view to show news
gridView = (GridView) findViewById(R.id.news_gridview);
gridView.setAdapter(newsAdapter);
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(NewsList.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
Then in onStart() I'll get XML data from server then parse it and final parsed data will be stored in "parsedList" (100% I have data in this variable because I saw it in logcat).
#Override
protected void onStart() {
super.onStart();
String strNewsContent = "***";
...
newsAdapter.setData(parsedList);
newsAdapter.notifyDataSetChanged();
}
Finally this is my "NewsAdapter":
public class NewsAdapter extends BaseAdapter {
private LayoutInflater myInflater;
private NewsFeedItemList itemList;
public NewsAdapter(Context c) {
myInflater = LayoutInflater.from(c);
}
public void setData(NewsFeedItemList newsFeedItemList){
itemList = newsFeedItemList;
Log.i("NewsAdapter", "Parsed list passed to the adapter.");
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null) {
convertView = myInflater.inflate(R.layout.grid_news, null);
holder = new ViewHolder();
holder.ivIcon = (TextView) convertView.findViewById(R.id.news_icon);
holder.tvLabel = (TextView) convertView.findViewById(R.id.news_label);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ivIcon.setText(itemList.getImage().get(position));
holder.tvLabel.setText(itemList.getTitle().get(position));
Log.i("Position is>>>>:", Integer.toString(position));
return convertView;
}
static class ViewHolder {
TextView ivIcon;
TextView tvLabel;
}
}
The format of "grid_news" is like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/news_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_contentdescription"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/news_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="10dip" />
</RelativeLayout>
I have no idea why I can't see the result in my emulator/device.
I think it is because of getCount() returning 0; shouldn't it be itemList.size()? in news NewsAdapter.