http://pastebin.com/UhP3RcpQ
download: http://www.mediafire.com/?9d7uly1yysz1fi2
Main.java
----------------------
package home.customList;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Main extends ListActivity{
String[] countries;
int c=0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
countries = getResources().getStringArray(R.array.countries_array);
//Toast.makeText(this,"Main class",Toast.LENGTH_LONG).show();
Log.d("------------main class-----------", "start");
setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1,countries));
//Toast.makeText(this,"end of Main class",Toast.LENGTH_LONG).show();
Log.d("------------main class-----------", "end");
ListView listView = getListView();//getListView() from ListActivity //public class ListView
//listView.setTextFilterEnabled(true);
}
private class MyAdapter extends ArrayAdapter<String>
{
public MyAdapter(Context context, int resource, int textViewResourceId,String[] strings)
{
//Toast.makeText(Main.this,"getView() row="+c,Toast.LENGTH_LONG).show();
super(context, resource, textViewResourceId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
c++;
//Toast.makeText(Main.this,"getView() c="+c,Toast.LENGTH_LONG).show();
Log.d("------------getView()-----------c="+c, "c="+c);
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.list_item,parent,false);
String[] items=getResources().getStringArray(R.array.countries_array);
ImageView iv=(ImageView) row.findViewById(R.id.imageView1);
TextView tv=(TextView) row.findViewById(R.id.textView1);
EditText et=(EditText)row.findViewById(R.id.editText1);
CheckBox cb=(CheckBox)row.findViewById(R.id.checkBox1);
tv.setText(items[position]);
et.setText("my button");
cb.setClickable(true);
if(items[position].equals("bangladesh"))
{
iv.setImageResource(R.drawable.bangladesh);
}
else if(items[position].equals("england"))
{
iv.setImageResource(R.drawable.england);
}
else if(items[position].equals("usa"))
{
iv.setImageResource(R.drawable.usa);
}
else if(items[position].equals("russia"))
{
iv.setImageResource(R.drawable.russia);
}
else
{
iv.setImageResource(R.drawable.ic_launcher);
}
tv.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
Toast.makeText(getApplicationContext(),((TextView)v).getText(), Toast.LENGTH_SHORT).show();
}
});
Log.d("------------row=-----------"+row, "row="+row);
return row;
}
}
}
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="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
list_item.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="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="25sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.72" >
<requestFocus />
</EditText>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
res/values/country.xml
---------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="countries_array">
<item name="bangladesh">bangladesh</item>
<item name="usa">usa</item>
<item name="russia">russia</item>
<item name="england">england</item>
</string-array>
</resources>
download: http://www.mediafire.com/?9d7uly1yysz1fi2
Main.java
----------------------
package home.customList;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Main extends ListActivity{
String[] countries;
int c=0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
countries = getResources().getStringArray(R.array.countries_array);
//Toast.makeText(this,"Main class",Toast.LENGTH_LONG).show();
Log.d("------------main class-----------", "start");
setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1,countries));
//Toast.makeText(this,"end of Main class",Toast.LENGTH_LONG).show();
Log.d("------------main class-----------", "end");
ListView listView = getListView();//getListView() from ListActivity //public class ListView
//listView.setTextFilterEnabled(true);
}
private class MyAdapter extends ArrayAdapter<String>
{
public MyAdapter(Context context, int resource, int textViewResourceId,String[] strings)
{
//Toast.makeText(Main.this,"getView() row="+c,Toast.LENGTH_LONG).show();
super(context, resource, textViewResourceId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
c++;
//Toast.makeText(Main.this,"getView() c="+c,Toast.LENGTH_LONG).show();
Log.d("------------getView()-----------c="+c, "c="+c);
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.list_item,parent,false);
String[] items=getResources().getStringArray(R.array.countries_array);
ImageView iv=(ImageView) row.findViewById(R.id.imageView1);
TextView tv=(TextView) row.findViewById(R.id.textView1);
EditText et=(EditText)row.findViewById(R.id.editText1);
CheckBox cb=(CheckBox)row.findViewById(R.id.checkBox1);
tv.setText(items[position]);
et.setText("my button");
cb.setClickable(true);
if(items[position].equals("bangladesh"))
{
iv.setImageResource(R.drawable.bangladesh);
}
else if(items[position].equals("england"))
{
iv.setImageResource(R.drawable.england);
}
else if(items[position].equals("usa"))
{
iv.setImageResource(R.drawable.usa);
}
else if(items[position].equals("russia"))
{
iv.setImageResource(R.drawable.russia);
}
else
{
iv.setImageResource(R.drawable.ic_launcher);
}
tv.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
Toast.makeText(getApplicationContext(),((TextView)v).getText(), Toast.LENGTH_SHORT).show();
}
});
Log.d("------------row=-----------"+row, "row="+row);
return row;
}
}
}
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="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
list_item.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="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="25sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.72" >
<requestFocus />
</EditText>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
res/values/country.xml
---------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="countries_array">
<item name="bangladesh">bangladesh</item>
<item name="usa">usa</item>
<item name="russia">russia</item>
<item name="england">england</item>
</string-array>
</resources>
No comments:
Post a Comment