Listview tüm itemleri göstermiyor.
Merhaba.Custom Listview oluşturdum.25 tane eleman var fakat sadece 17 tanesini listeliyor geri kalan 8 elaman listede görünmüyor.Kodlarımı paylaşıyorum sorun ne olabilir acaba?
Bu listeye elemanları aktardığım aktivite:
package com.canli.tvyayinlari;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
public class YerliList extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
// Create the list fragment and add it as our sole content.
if (fm.findFragmentById(android.R.id.content) == null) {
AppListFragment list = new AppListFragment();
fm.beginTransaction().add(android.R.id.content, list).commit();
}
}
/**
* A custom Loader that loads all of the Station
*/
public static class StationListLoader extends
AsyncTaskLoader<List<Integer>> {
private List<Integer> stationsImage;
Context context;
public StationListLoader(Context context) {
super(context);
this.context = context;
}
/**
* This will load all the stations image Integer
*/
@Override
public List<Integer> loadInBackground() {
List<Integer> stationImage = new ArrayList<Integer>();
Resources rs = context.getResources();
for (int i = 9; i <= rs.getStringArray(R.array.yerli_tv).length; i++) {
int resID = rs.getIdentifier("yerli_" + i, "drawable",
context.getPackageName());
if (resID <= 0)
resID = rs.getIdentifier("station_default", "drawable",
context.getPackageName());
stationImage.add(resID);
}
return stationImage;
}
@Override
public void deliverResult(List<Integer> images) {
if (isReset()) {
}
stationsImage = images;
if (isStarted()) {
super.deliverResult(images);
}
}
@Override
protected void onStartLoading() {
if (stationsImage != null) {
deliverResult(stationsImage);
}
forceLoad(); // *********** important
}
/**
* Handles a request to stop the Loader.
*/
@Override
protected void onStopLoading() {
cancelLoad();
}
/**
* Handles a request to cancel a load.
*/
@Override
public void onCanceled(List<Integer> apps) {
super.onCanceled(apps);
}
/**
* Handles a request to completely reset the Loader.
*/
@Override
protected void onReset() {
super.onReset();
onStopLoading();
}
/**
* Helper function to take care of releasing resources associated with
* an actively loaded data set.
*/
protected void onReleaseResources(List<Integer> apps) {
}
}
public static class AppListFragment extends SherlockFragment implements
LoaderManager.LoaderCallbacks<List<Integer>>, OnItemClickListener {
// This is the Adapter being used to display the list's data.
private DrawableYerliListAdapter mAdapter;
private ListView listView;
private ProgressBar progressBar;
private TextView textView;
private FrameLayout layout;
// private PlayBar playBar;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().setTitle(getResources().getString(R.string.app_name));
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
}
@Override
public Loader<List<Integer>> onCreateLoader(int id, Bundle args) {
return new StationListLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<List<Integer>> loader,
List<Integer> data) {
progressBar.setVisibility(View.GONE);
layout.setVisibility(View.VISIBLE);
if (data.size() == 0) {
textView.setText("No Stations Found");
textView.setVisibility(View.VISIBLE);
}
mAdapter.setData(data);
mAdapter.notifyDataSetChanged();
}
@Override
public void onLoaderReset(Loader<List<Integer>> loader) {
mAdapter.setData(null);
mAdapter.notifyDataSetChanged();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View v = inflater.inflate(R.layout.yerlikanal_list, container,
false);
listView = (ListView) v.findViewById(R.id.list);
progressBar = (ProgressBar) v.findViewById(R.id.load);
textView = (TextView) v.findViewById(R.id.empty);
layout = (FrameLayout) v.findViewById(R.id.list_show);
mAdapter = new DrawableYerliListAdapter(getActivity());
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(this);
progressBar.setVisibility(View.VISIBLE);
layout.setVisibility(View.GONE);
getLoaderManager().initLoader(0, null, this);
return v;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long l) {
Intent intent = new Intent(getActivity(), TVDetayYerli.class);
intent.putExtra("station_id", position);
intent.putExtra("station_image",
mAdapter.getImageResource(position));
intent.putExtra("station_name", mAdapter.getStationName(position));
startActivity(intent);
}
}
@Override
protected void onDestroy() {
try {
super.onDestroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Bu ise custom listview adapter aktivitesi:
package com.canli.tvyayinlari;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class DrawableYerliListAdapter extends BaseAdapter {
private List<Integer> list;
private final String[] stationName;
public DrawableYerliListAdapter(Context context) {
list = new ArrayList<Integer>();
stationName = context.getResources().getStringArray(R.array.yerli_tv);
}
@Override
public int getCount() {
if (list == null)
return 0;
return list.size();
}
@Override
public Object getItem(int arg0) {
return list.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.yerlikanal_list_item,
parent, false);
}
Integer data = list.get(position);
TextView nameView = (TextView) convertView.findViewById(R.id.title);
nameView.setText(stationName[position]);
ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
imageView.setImageResource(data);
return convertView;
}
public int getImageResource(int position) {
return list.get(position);
}
public String getStationName(int position) {
return stationName[position];
}
public void setData(List<Integer> data) {
list = data;
}
}