ListView has bugs on 4.4 KitKat? - android

I am using TwoWayView library from Lucas to create a horizontal ListView.
Everything works fine on GS3, Galaxy Note 2 Android 4.1.2 & Android 4.3.
However, I installed my app on my coworker Motorola G Android 4.44, and the ListView did not show any image. I can click on them, but I can't see any image. It only shows red or transparent color.
ListView Adpater:
public class ListViewAdapter extends BaseAdapter {
private List<ListViewObject> ObjectList;
private Context mContext;
public ListViewAdapter(Context context, List<ListViewObject> newList){
this.mContext = context;
this.ObjectList = newList;
}
#Override
public int getCount() {
return ObjectList.size();
}
#Override
public ListViewObject getItem(int position) {
return ObjectList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.listview_layout, parent, false);
viewHolder.imageView = (ImageView)convertView.findViewById(R.id.ListViewImage);
viewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.ListViewLayout);
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder)convertView.getTag();
}
Picasso.with(mContext)
.load(getItem(position).getImageUrl())
.resize(100, 100)
.centerCrop()
.into(viewHolder.imageView);
return convertView;
}
class ViewHolder {
RelativeLayout layout;
ImageView imageView;
}
}
ListView Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ListViewLayout"
android:layout_width="52dp"
android:layout_height="43dp" >
<ImageView
android:id="#+id/ListViewImage"
android:layout_width="50dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:layout_marginLeft="2px"
android:layout_marginTop="2px" />
Main Layout:
<org.lucasr.twowayview.TwoWayView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/TwoWayView"
style="#style/TwoWayView"
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_marginTop="595dp"
android:background="#color/transparent"
android:drawSelectorOnTop="true" />
MainActivity:
public void ListView_Load() {
for (File file : listFile){
mListViewObject = new ListViewObject();
mListViewObject.setImageUrl("file:///" + file.getAbsolutePath());
ListViewObject_List.add(mListViewObject);
}
listViewAdapter = new ListViewAdapter(this, ListViewObject_List);
TwoWayListView.setAdapter(listViewAdapter);
}
can someone please please guide me on this?
Thank you very much for your help.

Related

in gridview adapter class imageview set wrap content the images are blink while running in android?

I Created custom grid view with product list based on web service(json).but i facing new issue.when i set size(100dp) for image view height & width it working perfectly.but i set wrap_content or match parent it's view images are blink & blink again..
my fragment class :
public class HorizontalAdapter extends BaseAdapter {
private ArrayList<HomeCategoriesData> mArrayList;
private Context mContext;
private LayoutInflater mLayoutInflater;
public HorizontalAdapter(Activity homeActivity, ArrayList<HomeCategoriesData> mArrayList) {
this.mContext = homeActivity;
this.mArrayList = mArrayList;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return mArrayList.size();
}
#Override
public Object getItem(int position) {
return mArrayList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mViewHolder;
if (convertView == null) {
mViewHolder = new ViewHolder();
convertView = mLayoutInflater.inflate(R.layout.item_categories_item, null);
mViewHolder.mTvName = (TextView) convertView.findViewById(R.id.tv_categories_name);
mViewHolder.mIvimage = (ImageView) convertView.findViewById(R.id.iv_categories_img);
convertView.setTag(mViewHolder);
} else {
mViewHolder = (ViewHolder) convertView.getTag();
}
mViewHolder.mTvName.setText(mArrayList.get(position).getName());
Picasso.with(mContext).load(mArrayList.get(position).getCat_img()).into(mViewHolder.mIvimage);
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,mArrayList.get(position).getName(),Toast.LENGTH_SHORT).show();
//calling fragment from adatper class...
SellerSubCategoryFragment frag = new SellerSubCategoryFragment();
FragmentManager fm = ((MainActivity)mContext).getSupportFragmentManager();
Bundle bundle = new Bundle();
bundle.putString("id", String.valueOf(mArrayList.get(position).getId()));
frag.setArguments(bundle);
fm.beginTransaction().replace(R.id.content_frame,frag).addToBackStack(null).commit();
}
});
return convertView;
}
private class ViewHolder {
TextView mTvName;
ImageView mIvimage;
}
}
my adapter class xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_categories_img"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/tv_categories_name"
style="#android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_top_categories_name_5"
android:gravity="center"
android:lines="1"
android:textColor="#color/black" />
</LinearLayout>
my out put issue are ,
so what i do? and what is the problem.why i cannot set wrap_content or match_parent in this grid view?. my custom grid view are ExpandapleHeightGridView

How can I make an android xml layout for Category and CategoryItem

I'am new in using java and android studio and i was wondering how can i make a layout like this in 1 activity. myImage
What you are looking for is a Listview adapter
public class ExampleAdapter extends BaseAdapter {
List<Product> products;
private Activity context;
#Override
public int getCount() {
return products.size();
}
public ExampleAdapter(List<Product> products, Activity context) {
this.products = products;
this.context = context;
}
#Override
public Object getItem(int position) {
return products.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final Product product = products.get(position);
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.row_shopping_item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.getProductTextView().setText(product.getName());
holder.getProductImageView(). setImageResource(product.getPicture());
return convertView;
}
private class ViewHolder {
private final TextView productTextView;
private final ImageView productImageView;
private ViewHolder(View wrapperView) {
productTextView = (TextView) wrapperView.findViewById(R.id.tvName);
productImageView = (TextView) wrapperView.findViewById(R.id.ivPicture);
}
public TextView getProductTextView() {
return productTextView;
}
public ImageView getProductImageView() {
return productImageView;
}
}
}
This adapter needs a layout to define what the rows will look like. This will be something like this
<?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="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_gravity="center_vertical"
android:layout_width="50dp"
android:id="#+id/ivPicture"
android:layout_height="50dp" />
<TextView
android:id="#+id/tvName"
android:text="Product 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Lastly in your activity where you want to display the overview you will need to use a listview and set the adapter
final ExampleAdapter adapter = new ExampleAdapter(list, this);
listview.setAdapter(adapter);

How to create a list as below picture?

A setting picture
How to do that in android?
Before I used to referencescreen but it could'n use icon for each item.
It is a simple Listview. Refer the following code and replace the list_row with the list row design .xml that you want. This should help.
public class ListAdapter extends BaseAdapter {
LayoutInflater inflater;
View row;
public static List<String> list = new ArrayList<String>();
Context context;
class ViewHolder {
ImageView ivShare;
}
public ListAdapter(Context context, List<String> _list) {
this.context = context;
this.list = _list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
ViewHolder holder;
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_row, parent, false);
holder = new ViewHolder();
holder.ivShare = (ImageView) convertView
.findViewById(R.id.iv_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ivShare.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
return convertView;
}
}
Use ListView with CustomAdapter for doing this.
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView lv_applicationlist;
ApplicationListingAdapter adapter;
ArrayList<Integer> app_image=new ArrayList<>();
ArrayList<String> app_name=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv_applicationlist = (ListView) findViewById(R.id.lv_applicationlist);
app_name.add("Camera");
app_name.add("Gallery");
app_name.add("Send");
app_name.add("Share");
app_image.add(R.drawable.ic_menu_camera);
app_image.add(R.drawable.ic_menu_gallery);
app_image.add(R.drawable.ic_menu_send);
app_image.add(R.drawable.ic_menu_share);
adapter = new ApplicationListingAdapter(MainActivity.this, app_name,app_image);
lv_applicationlist.setAdapter(adapter);
}
}
activity_main.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/lv_applicationlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:listSelector="#android:color/transparent" />
</LinearLayout>
ApplicationListingAdapter.java
public class ApplicationListingAdapter extends BaseAdapter {
private Activity activity;
private static LayoutInflater inflater = null;
ArrayList<String> app_name;
ArrayList<Integer> app_image;
public ApplicationListingAdapter(Activity a, ArrayList<String> application_name, ArrayList<Integer> application_image) {
activity = a;
app_name = application_name;
app_image = application_image;
inflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return app_name.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView tv_appname;
public ImageView iv_appicon;
public Switch mySwitch;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.application_list_row, parent, false);
holder = new ViewHolder();
holder.tv_appname = (TextView) vi.findViewById(R.id.tv_appname);
holder.iv_appicon = (ImageView) vi.findViewById(R.id.iv_appicon);
holder.mySwitch = (Switch) vi.findViewById(R.id.mySwitch);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.tv_appname.setText(app_name.get(position));
holder.iv_appicon.setImageResource(app_image.get(position));
if(app_name.get(position).equals("Send"))
{
holder.mySwitch.setVisibility(View.VISIBLE);
}else{
holder.mySwitch.setVisibility(View.GONE);
}
return vi;
}
}
application_list_row.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="wrap_content">
<ImageView
android:id="#+id/iv_appicon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/tv_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="Store App"
android:textSize="20dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:visibility="gone"
android:layout_gravity="center_vertical" />
</LinearLayout>
Output will be look like this :

Gridview refreshing its content everytime while scrolling

I am building a custom gridview and using picasso for image download.I heared that picasso will cache automatically. But when I scroll ,the images get refreshed.I think I have made a mistake. Please check my code and help me to find the bug.I have posted my code below.
public class MoviesGridAdapter extends BaseAdapter{
private Context context;
private ArrayList<Movie> movies;
private LayoutInflater inflater;
private View gridView;
private final String BASE_IMAGE_URL = ""; // unable to expose the link
private Picasso mPicasso;
public MoviesGridAdapter(Context context,ArrayList<Movie> movies) {
this.context = context;
this.movies = movies;
mPicasso = Picasso.with(context);
mPicasso.setIndicatorsEnabled(true);
}
#Override
public int getCount() {
return movies.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
gridView = convertView;
ViewHolder holder;
// when the view got recycled
if(gridView == null){
inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
gridView = new View(context);
holder = new ViewHolder();
gridView = inflater.inflate(R.layout.grid_inner_layout,null);
holder.movieView = (ImageView) gridView.findViewById(R.id.imageView);
gridView.setTag(holder);
} else {
// if the view still available
gridView = convertView;
holder = (ViewHolder) gridView.getTag();
}
// loading the image with picasso image loader
mPicasso.
.load(BASE_IMAGE_URL + movies.get(position).getPosterUrl())
.resize(500, 750)
.error(R.mipmap.ic_launcher)
.into(holder.movieView);
return gridView;
}
static class ViewHolder{
ImageView movieView;
}
}
gridview xml
<GridView
android:id="#+id/moviesGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="150dp"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
gridview item layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="250dp"
android:id="#+id/imageView"
android:background="#android:drawable/screen_background_dark_transparent"/>
</LinearLayout>
Thanks !

Android and ListView with a very poor and slow scroll

I have a customized listview. In this list, I have something like 15 items. When I am trying to scroll, the scroll is very slow and not smooth.
Here is my listView:
<ListView
android:id="#+id/AnnouncementsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:cacheColorHint="#00000000"
android:fastScrollEnabled="true"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
And here is my List Adapter:
public class AnnouncementsListAdapter extends BaseAdapter {
private static ArrayList<NewsAnnouncements_Database> announcementsArrayList;
private LayoutInflater mInflater;
public AnnouncementsListAdapter(Context context, ArrayList<NewsAnnouncements_Database> searchResults) {
announcementsArrayList = searchResults;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return announcementsArrayList.size();
}
public Object getItem(int position) {
return announcementsArrayList.get(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.announcements_customisation, null);
holder = new ViewHolder();
holder.AnnouncementsTitle = (TextView) convertView.findViewById(R.id.AnnouncementsTitle);
holder.AnnouncementsContent = (TextView) convertView.findViewById(R.id.AnnouncementsContent);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.AnnouncementsTitle.setText(Html.fromHtml(announcementsArrayList.get(position).getTitle()));
holder.AnnouncementsContent.setText(Html.fromHtml(announcementsArrayList.get(position).getContent()));
return convertView;
}
static class ViewHolder {
TextView AnnouncementsTitle;
TextView AnnouncementsContent;
}
}
try removing cacheColorHint attribute int he XML layout.

Categories

Resources