Hey guys i have a ListActivity... a very simple at that... and it keeps throwing NullPointer Exception though i have done it exactly as the Sample List7 except that i have used the Layout inflater... below is the code... Can u plz comment the error i have done here??
import java.util.Vector;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
public class CustomList extends ListActivity implements OnItemSelectedListener{
Vector<String> VTitle;
Vector<String> VDescription;
TextView display;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VTitle.addElement("First Title");
VTitle.addElement("Second Title");
VTitle.addElement("Third Title");
VTitle.addElement("Fourth Title");
VDescription.addElement("1 Description");
VDescription.addElement("2 Description");
VDescription.addElement("3 Description");
VDescription.addElement("4 Description");
display = (TextView)findViewById(R.id.display);
setListAdapter(new CustomAdapter(this));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
display.setText(VTitle.elementAt(position));
}
class CustomAdapter extends BaseAdapter {
protected Activity mContext;
public CustomAdapter(Activity context) {
mContext = context;
// TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return VTitle.size();
}
#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 position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
if(row==null) {
LayoutInflater inflater = mContext.getLayoutInflater();
row = inflater.inflate(R.layout.row,null);
}
TextView title = (TextView)row.findViewById(R.id.title);
title.setText(VTitle.elementAt(position));
TextView description = (TextView)row.findViewById(R.id.description);
description.setText(VDescription.elementAt(position));
ImageView image = (ImageView)row.findViewById(R.id.image);
switch(position){
case 0:
image.setImageResource(R.drawable.check);
break;
case 1:
image.setImageResource(R.drawable.dos);
break;
case 2:
image.setImageResource(R.drawable.smily);
break;
case 3:
image.setImageResource(R.drawable.wrong);
break;
}
return(row);
}
}
#Override
public void onItemSelected(AdapterView parent, View v, int position, long id) {
// TODO Auto-generated method stub
display.setText(VTitle.elementAt(position));
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
And the xmls are like this....
"main.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id = "#+id/display"
android:text="something"
/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:drawSelectorOnTop="false"
android:layout_height="0px">
</ListView>
</LinearLayout>
"row.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">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:text="Title"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:text="description"
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
VTitle and VDescription aren't initialized
Before accessing one of these attributes, you should :
VTitle = new Vector<String>();
VDescription = new Vector<String>();
Moreover in java, the first letter of an attribute name should be lowercase, and in android this first letter should be an m, to denote a member field.
Related
I have 24 EditTexts and I want to have one EditText in each row.
Note: this code is working properly, but I want to add one EditText in one row.
I want to add one EditText per row.
Means I want to set 24 EditTexts in 24 separate rows, not 24 EditText in one row.
This is lyt_listview_activity.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/listViewMain"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
And this is-lyt_listview_list.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:background="#android:color/white"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:textColor="#android:color/black"
android:layout_height="wrap_content"
android:text="15dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
This is -ListviewActivity.java
package com.example.testlistview;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class ListviewActivity extends Activity {
private String[] arrText =
new String[]{"Text1","Text2","Text3","Text4"
,"Text5","Text6","Text7","Text8","Text9","Text10"
,"Text11","Text12","Text13","Text14","Text15"
,"Text16","Text17","Text18","Text19","Text20"
,"Text21","Text22","Text23","Text24"};
private String[] arrTemp;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lyt_listview_activity) ;
arrTemp = new String[arrText.length];
MyListAdapter myListAdapter = new MyListAdapter();
ListView listView = (ListView) findViewById(R.id.listViewMain);
listView.setAdapter(myListAdapter);
}
private class MyListAdapter extends BaseAdapter{
#Override
public int getCount() {
// TODO Auto-generated method stub
if(arrText != null && arrText.length != 0){
return arrText.length;
}
return 0;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrText[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//ViewHolder holder = null;
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = ListviewActivity.this.getLayoutInflater();
convertView = inflater.inflate(R.layout.lyt_listview_list, null);
holder.textView1 = (TextView) convertView.findViewById(R.id.textView1);
holder.editText1 = (EditText) convertView.findViewById(R.id.editText1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ref = position;
holder.textView1.setText(arrText[position]);
holder.editText1.setText(arrTemp[position]);
holder.editText1.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// 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 afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
arrTemp[holder.ref] = arg0.toString();
}
});
return convertView;
}
private class ViewHolder {
TextView textView1;
EditText editText1;
int ref;
}
}
}
In lyt_listview_list.xml you only have one EditText.
Those are your rows, and therefore, there's only one EditText (and a TextView) in each row
How many rows you see is determined by getCount(), and that's returning arrText.length, or 24.
As far as "adding another row". You can't add anything to an array. You need to use an Arraylist in your adapter. In which case, you'd likely want ArrayAdapter and not BaseAdapter
am creating an android application whereby am required to create a gridview with clickable image buttons each leading to a different activities.Also the gridview should be scrollable since i have many buttons to add .Can anyone help on how to do this? thank you.
Here is a sample of what am trying to do:
sample clickable gridview:
activitymain.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:orientation="vertical"
tools:context=".MainActivity" >
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:numColumns="3" >
</GridView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textStyle="bold"
android:text=" Computer Languages..." />
</RelativeLayout>
programlist.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" >
<ImageView
android:id="#+id/imageView1"
android:layout_gravity="center"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
</LinearLayout>
In MainActivity.java
package com.gnetspace.simplegridview;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.AdapterView;
import android.widget.GridView;
public class MainActivity extends Activity {
GridView gv;
Context context;
ArrayList prgmName;
public static String [] prgmNameList={"Let Us C","c++","JAVA","Jsp","Microsoft .Net","Android","PHP","Jquery","JavaScript"};
public static int [] prgmImages={R.drawable.images,R.drawable.images1,R.drawable.images2,R.drawable.images3,R.drawable.images4,R.drawable.images5,R.drawable.images6,R.drawable.images7,R.drawable.images8};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv=(GridView) findViewById(R.id.gridView1);
gv.setAdapter(new CustomAdapter(this, prgmNameList,prgmImages));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Create a folder by name drawable in res directory.
public static int [] prgmImages={R.drawable.images,R.drawable.images1,R.drawable.images2,R.drawable.images3,R.drawable.images4,R.drawable.images5,R.drawable.images6,R.drawable.images7,R.drawable.images8};
Create CustomAdapter and paste the following code.
package com.gnetspace.simplegridview;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class CustomAdapter extends BaseAdapter{
String [] result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, int[] prgmImages) {
// TODO Auto-generated constructor stub
result=prgmNameList;
context=mainActivity;
imageId=prgmImages;
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 stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView tv;
ImageView img;
}
#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.program_list, null);
holder.tv=(TextView) rowView.findViewById(R.id.textView1);
holder.img=(ImageView) rowView.findViewById(R.id.imageView1);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);
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 source link is caveofprograming
I tried everything. I tested by copy pasting the example here from developer website but still didnt do work. it just shows a blank space whee the gridview was supposed to come. Here is my code.
EnterApp.java
package com.locationremind.app;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;
public class EnterApp extends Activity {
Context con;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
con=this;
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.enterapp);
GridView gridView=(GridView) findViewById(R.id.grid_menu);
gridView.setAdapter(new MyAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
if(position==0)
startActivity(new Intent(getBaseContext(),LocationReminderActivity.class));
else
Toast.makeText(getBaseContext(), "Item"+position+"not Allocated yet",Toast.LENGTH_SHORT).show();
}
});
}
}
MyAdapter.java
package com.locationremind.app;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter {
Context context;
public MyAdapter(Context c) {
context = c;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
#Override
public Object getItem(int pos) {
// TODO Auto-generated method stub
return null;
}
#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
TextView tv;
/*ImageView imageView;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();*/
if(convertView==null)
{
tv=new TextView(context);
tv.setLayoutParams(new GridView.LayoutParams(85,85));
}
else
tv=(TextView)convertView;
tv.setBackgroundResource(thumbsID[position]);
tv.setMinimumHeight(128);
tv.setMinimumWidth(128);
tv.setLayoutParams(new GridView.LayoutParams(85,85));
tv.setText(text[position]);
return tv;
}
private Integer[] thumbsID={R.drawable.gridview_icon,R.drawable.icn};
private String[] text={"Select Location Using GPS","Select Location Using Wi-Fi",
"Select Location Using Network","Settings"};
}
enterapp.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/Rlayout"
>
<ImageView
android:id="#+id/img_icon"
android:src="#drawable/android"
android:maxWidth="80dp"
android:maxHeight="80dp"
android:layout_width="64px"
android:layout_height="64px"
android:contentDescription="logo-icon"/>
<GridView
android:id="#+id/grid_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</LinearLayout>
you mistake lies in your adapter as
#Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
saying you dont have any item to display that is why its not showing any element.
to solve this change your getCount() like this
#Override
public int getCount() {
// TODO Auto-generated method stub
return thumbsID.length;
}
getCount returns 0, that's why!
public int getCount() {
// TODO Auto-generated method stub
return text.lenght;
}
You are value is not coming because in your adapter getCount() method is returning 0. put some values on that. or if u put the list as argument in adapter, the u can take that list size as the return for the getCount().
I need to make a listview keep the selected view highlighted until another item is chosen, in that case the previous view removes the highlight and the latest clicked gets the highlight.
I tried not to do this and with a radio button but it isnt working.
It's actually pretty easy:
In the custom layout for the individual listview item, make sure it has the attribute:
android:background="?android:attr/activatedBackgroundIndicator" >
By way of example, here's a listview item layout from the HoneycombGallery sample that ships with the SDK (located in the title_list_item.xml file:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:gravity="bottom"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="?android:attr/activatedBackgroundIndicator" >
</TextView>
That attribute will cause the background color to change based on whether the individual list item is selected or not.
i m novice to android so i found this question interesting and finally i succeeded after 1 and half hour ;-)
here is the code:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<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>
listinflater.xml
android:id="#+id/tvItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
PreservelistitemActivity.java
package com.mehuljoisar;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class PreservelistitemActivity extends Activity {
//declaring variable
ListView listView1;
MyAdapter adapter1;
Integer length,i;
String[] data = {"Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh","Mehul","Milind","Aamir","Amitabh"};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//binding to the view
listView1 = (ListView)findViewById(R.id.listView1);
//set adapter
adapter1=new MyAdapter(PreservelistitemActivity.this,data);
listView1.setAdapter(adapter1);
}
public class MyAdapter extends BaseAdapter{
private final Activity context;
private final String[] data;
public MyAdapter(Activity context,
String[] data) {
// TODO Auto-generated constructor stub
super();
this.context=context;
this.data=data;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return data.length;
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.listinflater, null);
final TextView tvItem = (TextView)convertView.findViewById(R.id.tvItem);
tvItem.setText(data[position]);
listView1.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
/* length=parent.getAdapter().getCount();
for(i=0;i<length;i++)
{
//clear
if(i==position)
{
//set
}
}
*/
v.setSelected(true);
}
});
return convertView;
}
}
}
I was trying a sample program to understand the behavior of the dynamic GridView. When I tried to execute the program I got a run-time exception at texts.setText(str[position]); in the .java file.
.java
package GridView_dynamic.grid;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
public class GridView_dynamic extends Activity {
/** Called when the activity is first created. */
TextView select;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
select = (TextView)findViewById(R.id.text);
GridView grid = (GridView)findViewById(R.id.grid);
grid.setAdapter(new my_Adapter(this));
}
public class my_Adapter extends BaseAdapter{
String[] str = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
public Context context;
public my_Adapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return str.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#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
if(convertView == null){
Toast.makeText(context,"convertView is NULL", Toast.LENGTH_LONG).show();
}
TextView texts;
texts = (TextView)convertView;
//texts = (TextView)findViewById(R.id.text);
texts.setText(str[position]);
return texts;
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#0000aa"
android:textColor="#00aa00"
/>
<GridView
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#aaaaaa"
/>
</LinearLayout>
You get a NullPointerException because when you get a null convertView(the list is first built) you don't create a new TextView. Your getView() method should be:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
Toast.makeText(context,"convertView is NULL", Toast.LENGTH_LONG).show();
//if convertView is null is your job to make a new View
convertView = new TextView(context);
}
((TextView)convertView).setText(str[position]);
return convertView;
}
By the looks of it you never actually instantiate the TextView in getView. The following code will create a new textView if convertView is null.
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
convertView = new TextView(GridView_dynamic.this);
((TextView)convertView).setText(str[position]);
return convertView;
}
Hope this helps!