4) and Finally Create Activity for show Image on listview:-
public class Ecard extends Activity {
private Bundle ext;
private ImageButton back;
private TextView title;
private GridView grid_main;
public ListAdapter imgadp;
private AdView adView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ext=getIntent().getExtras();
setContentView(R.layout.ecard);
grid_main = (GridView)findViewById(R.id.gridView1);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.header1);
back=(ImageButton)findViewById(R.id.header_left_btn);
//next=(ImageButton)findViewById(R.id.header_right_btn);
title=(TextView)findViewById(R.id.header_text);
title.setText(ext.getString("title"));
new AddTask().execute();
back.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
grid_main.setOnItemClickListener(new GridView.OnItemClickListener()
{ public void onItemClick(AdapterView<?> a, View v, int i, long l)
{
try
{
Intent t = new Intent();
t.setClass(Ecard.this,Ecardfull.class);
Bundle b=new Bundle();
b.putString("title", "Full Wallpaper");
b.putInt("index", i);
t.putExtras(b);
startActivity(t);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Nay, cannot get the selected index"); }
}
});
}
class AddTask extends AsyncTask<Void,Void, Void> {
private ProgressDialog dialog;
protected void onPreExecute() {
dialog = new ProgressDialog(Ecard.this);
dialog.setMessage("Retrieving data ...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Void doInBackground(Void... unused) {
ImageData.loaddata();
imgadp=new ImageAdapter(Ecard.this,ImageData.icon,ImageData.name);
return(null);
}
protected void onProgressUpdate(Void... unused) {
// grid_main.setAdapter(imgadp);
}
protected void onPostExecute(Void unused) {
dialog.dismiss();
grid_main.setAdapter(imgadp);
}
}
public class ImageAdapter extends BaseAdapter{
Context mContext;
private Activity activity;
public ImageLoader imageLoader;
private LayoutInflater inflater=null;
private ArrayList<String> text;
private ArrayList<String> urls;
//public static final int ACTIVITY_CREATE = 10;
public ImageAdapter(Activity a,ArrayList<String> ur ,ArrayList<String> tx){
activity = a;
text=tx;
urls=ur;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
// TODO Auto-generated method stub
return urls.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public class ViewHolder{
public ImageView image;
public TextView text;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.ecardrow, null);
holder=new ViewHolder();
holder.image=(ImageView)vi.findViewById(R.id.imageView1);
holder.text=(TextView)vi.findViewById(R.id.textView1);
vi.setTag(holder);
}
else
{
holder=(ViewHolder)vi.getTag();
}
holder.text.setText(text.get(position));
// holder.image.setTag(urls.get(position));
imageLoader.DisplayImage(urls.get(position), activity, holder.image);
return vi;
}
}
}
public class Ecard extends Activity {
private Bundle ext;
private ImageButton back;
private TextView title;
private GridView grid_main;
public ListAdapter imgadp;
private AdView adView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ext=getIntent().getExtras();
setContentView(R.layout.ecard);
grid_main = (GridView)findViewById(R.id.gridView1);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.header1);
back=(ImageButton)findViewById(R.id.header_left_btn);
//next=(ImageButton)findViewById(R.id.header_right_btn);
title=(TextView)findViewById(R.id.header_text);
title.setText(ext.getString("title"));
new AddTask().execute();
back.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
grid_main.setOnItemClickListener(new GridView.OnItemClickListener()
{ public void onItemClick(AdapterView<?> a, View v, int i, long l)
{
try
{
Intent t = new Intent();
t.setClass(Ecard.this,Ecardfull.class);
Bundle b=new Bundle();
b.putString("title", "Full Wallpaper");
b.putInt("index", i);
t.putExtras(b);
startActivity(t);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Nay, cannot get the selected index"); }
}
});
}
class AddTask extends AsyncTask<Void,Void, Void> {
private ProgressDialog dialog;
protected void onPreExecute() {
dialog = new ProgressDialog(Ecard.this);
dialog.setMessage("Retrieving data ...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Void doInBackground(Void... unused) {
ImageData.loaddata();
imgadp=new ImageAdapter(Ecard.this,ImageData.icon,ImageData.name);
return(null);
}
protected void onProgressUpdate(Void... unused) {
// grid_main.setAdapter(imgadp);
}
protected void onPostExecute(Void unused) {
dialog.dismiss();
grid_main.setAdapter(imgadp);
}
}
public class ImageAdapter extends BaseAdapter{
Context mContext;
private Activity activity;
public ImageLoader imageLoader;
private LayoutInflater inflater=null;
private ArrayList<String> text;
private ArrayList<String> urls;
//public static final int ACTIVITY_CREATE = 10;
public ImageAdapter(Activity a,ArrayList<String> ur ,ArrayList<String> tx){
activity = a;
text=tx;
urls=ur;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
// TODO Auto-generated method stub
return urls.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public class ViewHolder{
public ImageView image;
public TextView text;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.ecardrow, null);
holder=new ViewHolder();
holder.image=(ImageView)vi.findViewById(R.id.imageView1);
holder.text=(TextView)vi.findViewById(R.id.textView1);
vi.setTag(holder);
}
else
{
holder=(ViewHolder)vi.getTag();
}
holder.text.setText(text.get(position));
// holder.image.setTag(urls.get(position));
imageLoader.DisplayImage(urls.get(position), activity, holder.image);
return vi;
}
}
}
No comments:
Post a Comment