How to customize the Android Share Intent for Facebook App. When I am using the share Intent, I am getting the following dialog.
But I am using Facebook sdk for post the image and text. And how to customize, when we click on Facebook icon in the above dialog it will navigate to my custom facebook dialog...
By using the below code u can get the list of social media networking apps list which are installed in your mobile.
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("text/plain");
List activities = ShareList.this.getPackageManager().queryIntentActivities(sendIntent, 0);
Send this list to Adapter class:
ListView lv=(ListView)findViewById(R.id.listView1);
final ShareAdapter adapter=new ShareAdapter(ShareList.this,activities.toArray());
lv.setAdapter(adapter);
Here is the Adapter class code:
public class ShareAdapter extends BaseAdapter {
Object[] items;
private LayoutInflater mInflater;
Context context;
public ShareAdapter(Context context, Object[] items) {
this.mInflater = LayoutInflater.from(context);
this.items = items;
this.context = context;
}
public int getCount() {
return items.length;
}
public Object getItem(int position) {
return items[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.singleitem, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.textView1);
holder.logo = (ImageView) convertView.findViewById(R.id.imageView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name
.setText(((ResolveInfo) items[position]).activityInfo.applicationInfo
.loadLabel(context.getPackageManager()).toString());
holder.logo
.setImageDrawable(((ResolveInfo) items[position]).activityInfo.applicationInfo
.loadIcon(context.getPackageManager()));
return convertView;
}
static class ViewHolder {
TextView name;
ImageView logo;
}}
Handling the specific social media network in the listview using the below code:
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
ResolveInfo info = (ResolveInfo) adapter.getItem(arg2);
if(info.activityInfo.packageName.contains("facebook")) {
new PostToFacebookDialog(context, body).show();
//here u can write your own code to handle the particular social media networking apps.
Toast.makeText(getApplicationContext(), "FaceBook", Toast.LENGTH_LONG).show();
} else {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "body");
((Activity)ShareList.this).startActivity(intent);
}
}
});
I used Venu's solution to get the "customized share intent" working. I just had little trouble by creating the xml.. So here I want to show other Android beginner how to add custom_share_list_white.xml. Maybe it will help others to get it working, too.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:footerDividersEnabled="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Large Text"
android:id="#+id/tv_share_adapter"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
in ShareAdapter.java:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_share_list_white, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.tv_share_adapter);
holder.logo = (ImageView) convertView.findViewById(R.id.imageView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(((ResolveInfo) items[position]).activityInfo
.applicationInfo.loadLabel(context.getPackageManager()).toString());
holder.logo.setImageDrawable(((ResolveInfo) items[position]).activityInfo
.applicationInfo.loadIcon(context.getPackageManager()));
return convertView;
}
Related
I have simple list which suppose to display all the rows from DB table. However, it shows only one row in the list view.
Though, it receives all the rows from the DB (verified the size of configArrayList), but displays only the first row and discards others.
Here is the Activity and Custom Adapter.
Main Activity :
ArrayList<HashMap<String, String>> configArrayList = dbTools.getAllConfig(); // Returns 4 rows
ArrayList<ConfigEntity> configMenu = new ArrayList<>();
if (!(configArrayList.isEmpty()))
{
Iterator<HashMap<String, String>> iterator = configArrayList.iterator();
while (iterator.hasNext())
{
HashMap<String, String> configMap = iterator.next();
// ConfigEntity contains two members Name, ID and their setter, getter
ConfigEntity entity = new ConfigEntity();
entity.setID(configMap.get("ID"));
entity.setName(String.valueOf(configArrayList.size()));
// Set Name as Size to verify the list size is grater than 1. (Size is 4)
configMenu.add(entity);
}
}
if (!(configMenu.isEmpty()))
{
ListAdapter adapter = new ConfigListAdapter(this, configMenu);
ListView theListView = (ListView) findViewById(R.id.config_list_listView);
theListView.setAdapter(adapter);
}
Here is the Custom Adapter :
public class ConfigListAdapter extends BaseAdapter {
private ArrayList<ConfigEntity> entityList;
private LayoutInflater layoutInflater;
public ConfigListAdapter(Context context, ArrayList<ConfigEntity> entityList) {
this.entityList = entityList;
layoutInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return entityList.size();
}
#Override
public Object getItem(int position) {
return entityList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.config_list_row_layout, null);
holder = new ViewHolder();
holder.nameTextView = (TextView) convertView.findViewById(R.id.config_list_row_textView);
holder.idTextView = (TextView) convertView.findViewById(R.id.config_list_row_id);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ConfigEntity entity = entityList.get(position);
holder.nameTextView.setText(entity.getName());
holder.idTextView.setText(entity.getID());
return convertView;
}
static class ViewHolder {
TextView nameTextView;
TextView idTextView;
}
}
main_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add New"
android:id="#+id/config_list_addConfig_button"
android:layout_gravity="right"
android:onClick="addNewConfig" />
<ListView
android:id="#+id/config_list_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="5dp">
</ListView>
</LinearLayout>
</ScrollView>
config_list_listView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/margin_20dp">
android:layout_marginRight="#dimen/margin_20dp">
<TextView
android:id="#+id/config_list_row_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginTop="#dimen/margin_10dp"
android:layout_marginLeft="#dimen/margin_20dp"
android:longClickable="true" />
<TextView
android:id="#+id/config_list_row_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
Please try this.
Change getView Method as follows
#Override
public View getView(int position, View convertView, ViewGroup parent) {
view=convertView;
ViewHolder holder;
if (convertView == null) {
view = layoutInflater.inflate(R.layout.config_list_row_layout, null);
holder = new ViewHolder();
holder.nameTextView = (TextView) view.findViewById(R.id.config_list_row_textView);
holder.idTextView = (TextView) view.findViewById(R.id.config_list_row_id);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
ConfigEntity entity = entityList.get(position);
holder.nameTextView.setText(entity.getName());
holder.idTextView.setText(entity.getID());
return view;
}
and Declare View view; as class level variable;
Hope it helps Thanks. Refer here :-https://androidruler.wordpress.com/2016/02/21/android-custom-listview-example/
I've created a custom listView which lists all installed apps on the device, in this list is the app icon, app name and a checkbox. I want to code the onCheckboxClicked method but I don't know where to place it, I've read it should be within the adapter but other examples i've been looking at have code within the main activity and I can't seem to get it working either way.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//retrieve currently installed apps
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
List<AppDetails> appList = new ArrayList<>();
for (Object object : pkgAppsList)
{
ResolveInfo info = (ResolveInfo) object;
Drawable icon = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);
String strAppName = info.activityInfo.applicationInfo.publicSourceDir.toString();
String strPackageName = info.activityInfo.applicationInfo.packageName.toString();
final String title = (String)((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : "???");
AppDetails tmp = new AppDetails(title, icon);
appList.add(tmp); //add title and icon into list
}
final ListView listview = (ListView) findViewById(R.id.listView);
final AppDetailsAdapter adapter = new AppDetailsAdapter(this, appList);
listview.setAdapter(adapter);
}
adapter:
public class AppDetailsAdapter extends BaseAdapter {
private List<AppDetails> data;
private Context context;
public AppDetailsAdapter(Context context, List<AppDetails> data) {
this.context = context;
this.data = data;
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
return data.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.custom_row_layout, null);
}
ImageView icon = (ImageView) view.findViewById(R.id.icon);
TextView text = (TextView) view.findViewById(R.id.text);
final AppDetails item = data.get(position);
text.setText(item.name);
icon.setImageDrawable(item.icon);
return view;
}
}
custom layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/icon"
android:layout_width="39dp"
android:layout_height="39dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:textSize="17sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:onClick="onCheckboxClicked"/>/>
</LinearLayout>
I've also read that the getView method needs to be modified to handle the checkbox but again I can't seem to do it with what I've tried so far
Replace your adapter's get view code with below code :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.custom_row_layout, null);
}
ImageView icon = (ImageView) view.findViewById(R.id.icon);
TextView text = (TextView) view.findViewById(R.id.text);
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox);
final AppDetails item = data.get(position);
text.setText(item.name);
icon.setImageDrawable(item.icon);
checkBox .setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Handle your conditions here
}
});
return view;
}
here setOnCheckedChangeListener is method that you have to handle .
In my gridViewAdapter I set the ImageResource to the .png object but it doesn't show in activity. Here's the adapter's function getView:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.photoSubscriptTextView = (TextView) row.findViewById(R.id.photoSubscriptTextView);
holder.photoInstanceImageView = (ImageView) row.findViewById(R.id.galleryMonumentPhotoImageView);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
final Photo photo = data.get(position);
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent;
if(photo.getPodpis().equals(getContext().getString(R.string.photo_add))){
intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
((Activity) context).startActivityForResult(Intent.createChooser(intent, "Select Picture"), 100);
}
else {
intent = new Intent(context, PhotoGallery.class);
intent.putExtra("photo", photo);
context.startActivity(intent);
}
}
});
holder.photoSubscriptTextView.setText(photo.getPodpis());
if(photo.getUri() != null)
aQuery.id(holder.photoInstanceImageView).image(photo.getUri());
else if(photo.getPodpis().equals(getContext().getResources().getString(R.string.photo_add))) {
holder.photoInstanceImageView.setImageResource(R.drawable.image_add);
}
return row;
And the 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="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:padding="5dp"
android:clickable="true"
android:focusable="true">
<!--android:background="#drawable/grid_color_selector"-->
<ImageView
android:id="#+id/galleryMonumentPhotoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/image_add">
</ImageView>
<TextView
android:id="#+id/photoSubscriptTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:textSize="12sp" >
</TextView>
</LinearLayout>
The main layout contains only the Relative Layout and GridView.
Can anybody tell me why image from resources that I set in adapter doesn't show in activity?
Just because you put the onClick() method inside of getView() does not mean it has access to temporary variables created within getView(). The item clicked will likely be a different one than the getView() method last processed. So, there is no connection between them.
You should instead put a onItemClick() listener on the ListView itself in your activity onCreate() or onCreateView() code. That method has the position of the item that was clicked, and you can then get that item from your ArrayList using the position.
Like this:
mListView.setOnItemClickListener(new ListView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long row_id) {
final Photo photo = data.get(position);
// etc.
}
}
I have a list view which displays only one record always, I've traced my program and find that there are 3 records in my arrayList which I'm passing to the listView adapter. After tracing into getView of list view I find that It executes more that 3 times with position of 0!
I have no idea what's the problem, please help me if you can.
activity_news.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:background="#color/background"
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=".News" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/lvNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" />
</ScrollView>
</RelativeLayout>
this is row template for listView: news_row.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="wrap_content"
android:background="#drawable/message_row_style"
android:layout_gravity="right"
android:gravity="right"
android:orientation="vertical" >
<LinearLayout
android:layout_marginTop="50dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#color/dark_purple"
android:layout_gravity="right"
android:gravity="right"
android:background="#color/red"
/>
<TextView
android:id="#+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/dark_purple"
android:layout_gravity="right"
android:background="#color/blue"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
newsAdapter.java:
public class NewsAdapter extends BaseAdapter{
private Context context;
private ArrayList<News> list;
private Activity activity;
public NewsAdapter(Context c,Activity activity,ArrayList<News> l) {
Log.d("Ehsan", "News Adapter Constructor");
context = c;
list = l;
this.activity = activity;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int i) {
return list.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.news_row, parent,false);
TextView title = (TextView) row.findViewById(R.id.txtTitle);
TextView date = (TextView) row.findViewById(R.id.txtDate);
News temp = list.get(position);
title.setText(temp.getTitle());
date.setText(temp.getsDate());
title.setTag(temp.getid());
title.setOnClickListener(onClickListener);
return row;
}
private OnClickListener onClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
String date = null,title = null,description = null;
int id=1;
Intent i = null;
News news = new News(activity);
news.load(id);
date = news.getsDate()+" - ";
title = news.getTitle();
description = news.getDescription();
i = new Intent(activity,ShowInfo.class);
i.putExtra("date", date);
i.putExtra("title", title);
i.putExtra("description", description);
activity.startActivity(i);
activity.finish();
}
};
}
Do following changes in your getView
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
ViewHolder holder=new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.news_row, parent,false);
TextView title = (TextView) row.findViewById(R.id.txtTitle);
TextView date = (TextView) row.findViewById(R.id.txtDate);
convertView.setTag(holder);
}
ViewHolder hold=(ViewHolder)convertView.getTag();
News temp = list.get(position);
hold.title.setText(temp.getTitle());
hold.date.setText(temp.getsDate());
title.setOnClickListener(onClickListener);
return row;
}
add this class in your adapter file
static class ViewHolder
{
TextView title;
TextView date;
}
You should call super in the constructor of your adapter change your adapter as following:
public class NewsAdapter extends ArrayAdapter<News>{
private Context context;
private ArrayList<News> list;
private Activity activity;
public NewsAdapter(Context c,Activity activity,ArrayList<News> l) {
super(c,-1,l);//<-- **pass your item list to super**
Log.d("Ehsan", "News Adapter Constructor");
context = c;
list = l;
this.activity = activity;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int i) {
return list.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.news_row, parent,false);
TextView title = (TextView) row.findViewById(R.id.txtTitle);
TextView date = (TextView) row.findViewById(R.id.txtDate);
News temp = list.get(position);
title.setText(temp.getTitle());
date.setText(temp.getsDate());
title.setTag(temp.getid());
title.setOnClickListener(onClickListener);
return row;
}
private OnClickListener onClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
String date = null,title = null,description = null;
int id=1;
Intent i = null;
News news = new News(activity);
news.load(id);
date = news.getsDate()+" - ";
title = news.getTitle();
description = news.getDescription();
i = new Intent(activity,ShowInfo.class);
i.putExtra("date", date);
i.putExtra("title", title);
i.putExtra("description", description);
activity.startActivity(i);
activity.finish();
}
};
}
How can I create something like this?
I want to have the "selected image" as the main view, and then a time line effect at the bottom; something like a Gallery would work, but that has been deprecated.
I'm thinking a HorizontalScrollView at the bottom, but will that recycle the views properly? Can I implement the ViewHolder pattern here?
What about StackView? I found this: http://www.gdgankara.org/2012/03/25/stackview-non-widget-sample/ which could be cool, but I couldn't find a lot of things about StackViews online, so I'm wondering how much it gets implemented?
I solved this problem by using a custom horizontal ListView by MUKESH YADAV
I changed his HorizontalImageAdapter.java class to use a CursorAdapter.
My solution here:
public class HorizontalImageAdapter extends CursorAdapter {
//...some initialization here
public HorizontalImageAdapter(Context context, Cursor c, int count) {
super(context, c, true);
this.context = (Activity) context;
this.count = count;
this.cursor = c;
inflater = LayoutInflater.from(context);
cursor.moveToFirst();
}
private static class ViewHolder {
public ImageView imageview;
public TextView textview;
public ImageView imageviewvideo;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
cursor.moveToPosition(position);
if (convertView == null) {
Log.d(TAG, "converView == null <<<<<<<<<<<<<<<<<<<<<<<<");
convertView = inflater.inflate(R.layout.activity_media_items, null);
holder = new ViewHolder();
holder.textview = (TextView) convertView.findViewById(R.id.tv_details_title);
holder.imageview = (ImageView) convertView.findViewById(R.id.iv_details_resource_image);
holder.imageviewvideo = (ImageView) convertView.findViewById(R.id.iv_details_resource_video);
convertView.setTag(holder);
} else {
Log.d(TAG, "converView != null >>>>>>>>>>>>>>>>>>>>>>>>");
}
//get the type of the item
type = cursor.getString(cursor.getColumnIndex(DatabaseHelper.FIELD_ITEM_TYPE));
if(type.equalsIgnoreCase("text")){
//handle for text item
}
if(type.equalsIgnoreCase("image")){
//handle for image item
}
if(type.equalsIgnoreCase("video")){
//handle for video item
}
return convertView;
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
String title = cursor.getString(cursor.getColumnIndex(DatabaseHelper.FIELD_TITLE));
String fileName = cursor.getString(cursor.getColumnIndex(DatabaseHelper.FIELD_RESOURCE));
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
View eachitem = inflater.inflate(R.layout.activity_media_items, parent, false);
holder.textview = (TextView) eachgrid.findViewById(R.id.tv_details_title);
holder.imageview = (ImageView) eachgrid.findViewById(R.id.iv_details_resource_image);
holder.imageviewvideo = (ImageView) eachgrid.findViewById(R.id.iv_details_resource_video);
eachgrid.setTag(holder);
return eachitem;
}
}
And the XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/black" >
<ImageView
android:id="#+id/selected_imageview"
android:layout_width="#dimen/exhibit_item_width"
android:layout_height="#dimen/exhibit_item_height"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:maxHeight="#dimen/exhibit_item_height"
android:maxWidth="#dimen/exhibit_item_width"
android:src="#drawable/logo" />
<RelativeLayout
android:id="#+id/gallery_relative_layout"
android:layout_width="wrap_content"
android:layout_height="#dimen/exhibit_items_height"
android:layout_gravity="bottom"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<com.example.testdatabase2.HorizontalView
android:id="#+id/gallery"
android:layout_width="match_parent"
android:layout_height="#dimen/exhibit_items_height"
android:layout_centerHorizontal="true"
android:smoothScrollbar="true"
android:spacing="20dip" >
</com.example.testdatabase2.HorizontalView >
</RelativeLayout>
</LinearLayout>