Customlistview not inflating - android

I was trying to implement simple customlistview.What i tried to do is to inflate a text and a picture inside each list row in the listview.I got no output i.e. layout was not inflating..I got a blank screen.I used 2 Java class and 2 xml files.Below is my code..Please let me know where is my mistake and what should i correct?
CListView.java
package com.example.customlistview;
public class Clistview extends Activity {
int p1[]={R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher};
String[] Shapes1={"circle","circle","circle","circle","circle"};
ListView lv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clistview);
lv=(ListView)findViewById(R.id.listView1);
CustomListViewAdapter clvadapter=new CustomListViewAdapter(Clistview.this,Shapes1,p1);
lv.setAdapter(clvadapter);
}
}
CustomListViewAdapter.java
package com.example.customlistview;
public class CustomListViewAdapter extends BaseAdapter {
Context context;
String shape1[];
int pic[];
public CustomListViewAdapter(Context c,String[] sh,int[] p)
{
this.context=c;
this.shape1=sh;
this.pic=p;
}
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
public String getItem(int pos) {
// TODO Auto-generated method stub
return shape1[pos];
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int pos, View v, ViewGroup vg) {
// TODO Auto-generated method stub
View itemview=v;
TextView tv1;
ImageView im1;
if(itemview==null)
{
LayoutInflater inflater=(LayoutInflater)((Activity)context).getLayoutInflater();
itemview=inflater.inflate(R.layout.clistview1,vg,false);
}
tv1=(TextView)itemview.findViewById(R.id.textView1);
im1=(ImageView)itemview.findViewById(R.id.imageView1);
tv1.setText(shape1[pos]);
im1.setImageResource(pic[pos]);
return itemview;
}
}
activity_clistview.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Clistview" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp" >
</ListView>
</RelativeLayout>
clistview1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
/>
</LinearLayout>

Inside CustomListViewAdapter, change this
public int getCount() {
// TODO Auto-generated method stub
return shape1.length;
}
It is an important function that decides the number of items in a ListView.

public int getCount() {
// TODO Auto-generated method stub
return 0;
}
You are returning 0 .
Return pic.length or shape1.length as per your requirement.
public int getCount() {
return pic.length;
}
Method getCount() returns the number of items in the datatset for the adapter.
getCount()

Related

Integrating Listview and search

Im having hard time integrating search in a custom listview. I have a listview using layout.xml and adapter then when I added search in my existing listview the search is working but the layout in not show in the list.Kindly click here for the file
Android Zip Click here.
Main Activity
public class MainActivity extends Activity{
EditText search;
ListView listview;
ArrayList<Person> list=new ArrayList<Person>();
ArrayList<Person> source=new ArrayList<Person>();
ArrayAdapter<Person> adapter;
AlertDialog.Builder builder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
this.search=(EditText) this.findViewById(R.id.editText1);
this.listview=(ListView) this.findViewById(R.id.listView1);
//populate source
//list.add(new Person(R.drawable.melvin,"Melvin ","PhD Educational Management"));
source.add(new Person(R.drawable.dennis,"Dennis ","Master in Information Technology"));
source.add(new Person(R.drawable.jonathan,"Jonathan ","PhD in Technological Management"));
source.add(new Person(R.drawable.bell,"Bell ","MS Information Technology"));
source.add(new Person(R.drawable.jennifer,"Jennifer ","PhD Technological Management"));
source.add(new Person(R.drawable.gian,"Gian","MS Information Technology"));
//delegatethe list to the adapter
adapter=new ArrayAdapter<Person>(this,android.R.layout.simple_list_item_1,list);
//delegate the adapter to the listview
this.listview.setAdapter(adapter);
//delegate a key watcher
this.search.addTextChangedListener(new TextWatcher(){
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
//clear the listview
list.clear();
//get match
String regex=arg0.toString();
Pattern p=Pattern.compile(regex);
for(int i=0;i<source.size();i++){
Matcher m=p.matcher((CharSequence) list.get(i));
while(m.find()){
list.add(source.get(i));
adapter.notifyDataSetChanged();
}
}
}
});
}
Adapter
package com.example.searchlist;
public class ItemAdapter extends BaseAdapter {
Context context;
ArrayList<Person> list;
LayoutInflater inflater;
public ItemAdapter(Context context, ArrayList<Person> list) {
super();
this.context = context;
this.list = list;
this.inflater=LayoutInflater.from(context);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
#Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
PersonHandler handler =null;
if(arg1==null){
arg1=inflater.inflate(R.layout.item_layout, null);
handler=new PersonHandler();
handler.iv=(ImageView) arg1.findViewById(R.id.imageView1);
handler.name=(TextView) arg1.findViewById(R.id.textView1);
handler.course=(TextView) arg1.findViewById(R.id.textView2);
arg1.setTag(handler);
}
else handler=(PersonHandler) arg1.getTag();
handler.iv.setImageResource(list.get(arg0).getImg());
handler.name.setText(list.get(arg0).getName());
handler.course.setText(list.get(arg0).getCourse());
return arg1;
}
static class PersonHandler{
ImageView iv;
TextView name, course;
}
}
layout
<?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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0000ff" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ff0000" />
</LinearLayout>
Activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4682b4"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:ems="10"
android:hint="SEARCH"
android:padding="10dp" >
<requestFocus />
</EditText>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#fafad2" >
</ListView>
</LinearLayout>

How to display grid view with images?

I'm trying to display grid view of images.I have tried the following code but my application gets force close after running.Where i have gone wrong?
My code:
AndroidGridLayoutActivity:
public class AndroidGridLayoutActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gv=(GridView)findViewById(R.id.grid_view);
gv.setAdapter(new ImageAdapter(this));
}
}
ImageAdapter.java:
public class ImageAdapter extends BaseAdapter {
private Context mcontext;
public Integer[] mThumbids={R.drawable.img9,R.drawable.img10,R.drawable.img11,R.drawable.img12,R.drawable.img13,R.drawable.img14};
public ImageAdapter(Context c)
{
mcontext=c;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbids.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbids[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView=new ImageView(mcontext);
imageView.setImageResource(mThumbids[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70,70));
return imageView;
}
}
main.xml:
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid_view"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:stretchMode="columnWidth"/>
public class MainActivity extends Activity {
GridView gv1;
GridViewAdapter madapter;
int arr[]={R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher};
String arr1[]={"ashu","hello","yes","no"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv1=(GridView)findViewById(R.id.gridView1);
madapter=new GridViewAdapter();
gv1.setAdapter(madapter);
}
class GridViewAdapter extends BaseAdapter{
#Override
public int getCount() {
// TODO Auto-generated method stub
return arr1.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater infla=getLayoutInflater();
View v=infla.inflate(R.layout.main1,null);
TextView tv1=(TextView)v.findViewById(R.id.textView1);
ImageView iv1=(ImageView)v.findViewById(R.id.imageView1);
tv1.setText(arr1[position]);
iv1.setBackgroundResource(arr[position]);
return v;
}}
}
activity_main.xml
<GridView
android:id="#+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
/> </RelativeLayout>
main1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:text="TextView" /> </RelativeLayout>

custom listview error: java.lang.unsupportedoperationexception: addview

I'm really new to android and I know you shouldnt paste whole codes but I honestly have no idea where the problem is.
Im trying to create a somewhat custom list view, with a text and an image, but keep geting this exception and have no idea how to solve it
02-13 13:23:06.477: E/AndroidRuntime(1834): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
so was hoping someone here could help me out. this is what my launcher activity looks like
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView list=(ListView) this.findViewById(R.id.list_view);
int[] stringIds=new int[2];
stringIds[0]=R.string.text1;
stringIds[1]=R.string.text2;
int[] imgIds=new int[2];
imgIds[0]=R.drawable.ic_launcher;
imgIds[1]=R.drawable.ic_launcher;
CustomAdapter custom=new CustomAdapter(this, stringIds, imgIds);
list.setAdapter(custom);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
My CustomAdapter:
public class CustomAdapter extends BaseAdapter {
Context context;
int[] stringIds;
int[] imgIds;
public CustomAdapter(Context context, int[]stringIds, int[] imgIds) {
this.stringIds=stringIds;
this.imgIds=imgIds;
this.context=context;
// TODO Auto-generated constructor stub
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
View finalView=convertView;
if(finalView==null){
LayoutInflater inflater=((Activity)context).getLayoutInflater();
finalView= inflater.inflate(R.layout.list_view_row, parent);
}
TextView txt=(TextView)finalView.findViewById(R.id.list_view_row_text_view);
ImageView img=(ImageView)finalView.findViewById(R.id.imageView1);
img.setImageResource(imgIds[position]);
return finalView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return this.stringIds.length;
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
}
activity_main.xml layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
list_view_row.xml layout
<?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/list_view_row_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Here:
finalView= inflater.inflate(R.layout.list_view_row, parent);
remove parent
finalView= inflater.inflate(R.layout.list_view_row, null);
or
finalView= inflater.inflate(R.layout.list_view_row, parent, false);
also use
setContentView(R.layout.activity_main);
before getting
ListView

How to add ImageView, TextView and Button in ListView in android

In my application I am trying to create a ListView that contains an ImageView a TextView and a Button. I have created a separate XML file and drag all the above mentioned elements in that XML and in my main java file I have created an Object of BaseAdapter and in the getView() method I have declared these elements but when I run the application I cant see the list. I haven't used the BaseAdapter, so I am missing with some code in order to view the List. I also want to apply some operations on the button so please let me know that code also.
Code for my main.xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Code for my list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="75dp"
android:layout_height="75dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="0dp"
android:layout_marginTop="15dp"
android:text="Medium Text"
android:textSize="15dp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="25dp"
android:text="Button" />
</LinearLayout>
Code for my main.java file:
public class CustomListActivity extends Activity {
/** Called when the activity is first created. */
ListView lv;
LayoutInflater inflator;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView)findViewById(R.id.listView1);
BaseAdapter bs = new BaseAdapter() {
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vw = inflator.inflate(R.layout.list_items, null);
ImageView img = (ImageView)findViewById(R.id.imageView1);
TextView tv = (TextView)findViewById(R.id.textView1);
Button btn = (Button)findViewById(R.id.button1);
return vw;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public int getCount() {
// TODO Auto-generated method stub
return 2;
}
};
}
}
Thanks in advance....
ok,
public class App_Adapter extends BaseAdapter implements OnClickListener{
private Activity mActivity;
private List<App_List> mList;
private static LayoutInflater inflater=null;
private PackageManager pm;
private String appclass;
private ApplicationTask mApplicationTask;
private String link=null;
public App_Adapter (FavouriteApp favouriteApp,List<App_List> mAppList, String appclass) {
// TODO Auto-generated constructor stub
this.mActivity= favouriteApp;
this.mList= mAppList;
this.appclass = appclass;
inflater = (LayoutInflater)mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pm=mActivity.getPackageManager();
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return mList.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View mView=convertView;
if (convertView == null)
mView = inflater.inflate(R.layout.app_adapter, parent,false);
App_List mAppList= mList.get(position);
**here i am setting two textview and one button**
((TextView) mView.findViewById(R.id.textView_appName)).setText(mAppList.getApp_Name());
((TextView) mView.findViewById(R.id.textView_appDescription)).setText(mAppList.getApp_Description());
boolean status = isAppInstalled(mAppList.getApp_Pkg());
Button btn = (Button) mView.findViewById(R.id.button_appStatus);
**// register the button for clicklistener**
btn.setOnClickListener(this);
return mView;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
and call this adapter class from your activity.
You are definitely missing lv.setAdapter(bs);

Android: BaseAdapter not showing elements

The app I'm struggling to make has a simple list and a button present in the bottom no matter what. My problem is that my custom BaseAdapter doesn't show elements. I know that since my elements are only a string I could use an ArrayAdapter, but the assignment requires it. The code:
class ListaOrase extends BaseAdapter{
private Activity context;
ArrayList<String> orase;
public ListaOrase(Activity context){
this.context=context;
orase=new ArrayList<String>();
}
public void add(String string){
orase.add(string);
}
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
public View getView (int position, View convertView, ViewGroup list) {
View element;
if (convertView == null)
{
LayoutInflater inflater = context.getLayoutInflater();
element = inflater.inflate(R.layout.lista, null);
}
else element = convertView;
TextView elementLista=(TextView)element.findViewById(R.id.elementLista);
elementLista.setText(orase.get(position));
return element;
}
}
public class WeatherAppActivity extends ListActivity {
Button buton;
ListaOrase lista;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lista=new ListaOrase(this);
buton=(Button)findViewById(R.id.buton);
setListAdapter(lista);
lista.add("Bucuresti");
lista.add("Sibiu");
}
}
My XML files go like this:
main.xml -- for the Activity
<?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="fill_parent"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/list"
android:layout_alignParentTop="true"/>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="add"
android:text="Add"
android:layout_gravity=""
/>
</RelativeLayout>
</RelativeLayout>
lista.xml -- for the list
<?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/elementLista"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The button "downstairs" opens a dialog that adds items to my list. It obviously doesn't work, but I think it's the BaseAdapter (ListaOrase) itself, as the intents throw no exceptions. I would be thankful if the items I hardcoded in would show up (Bucuresti and Sibiu).
What am I doing wrong?
Thank you very much! :)
Your code almost perfect issue is return orase.size() in getcount() method,you are returning 0, add unimplemented methods in ListaOrase class.
your ListaOrase should be like this:
class ListaOrase extends BaseAdapter{
private Activity context;
ArrayList<String> orase;
public ListaOrase(Activity context){
this.context=context;
orase=new ArrayList<String>();
}
public void add(String string){
orase.add(string);
}
public View getView (int position, View convertView, ViewGroup list) {
View element;
if (convertView == null)
{
LayoutInflater inflater = context.getLayoutInflater();
element = inflater.inflate(R.layout.lista, null);
}
else element = convertView;
TextView elementLista=(TextView)element.findViewById(R.id.elementLista);
elementLista.setText(orase.get(position));
Log.e("",orase.get(position));
return element;
}
public int getCount() {
// TODO Auto-generated method stub
return orase.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}
hope this helps
getCount method was really returning 0 so consquently getView() wasn't being called. When I changed to:
getcount() {
return arrayObject.Size();
}

Categories

Resources