as you can see subject i couldn't solve this problem about 2 days i don't know why i couldn't find any reason and I'm not a professional just beginner thanks aldready
MainActivity.java
Here this my MainActivity
public class MainActivity extends AppCompatActivity {
private ArrayList<Person> persons;
private ListView listView;
private CustomListViewAdapter listViewAdapter;
String Datas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
fillArrayList(persons);
}
private void initialize() {
persons = new ArrayList<Person>();
listView = (ListView) findViewById(R.id.person_list_view);
listViewAdapter = new CustomListViewAdapter(MainActivity.this,persons);
listView.setAdapter(listViewAdapter);
}
private void fillArrayList(ArrayList<Person>persons){
String veriDizisi[] =new String[500];
int sayi=0;
int sayac=0;
try{
final StringBuilder builder = new StringBuilder();
Document doc = Jsoup.connect("http://www.planecrashinfo.com/recent.htm").get();
String title = doc.title();
Elements links = doc.select("tr");
// builder.append(title).append("\n");
for (Element link : links) {
if (sayi>=1){
builder.append("\n").append("").append(link.text());
Datas= builder.toString();
sayi++;
}
else {
sayi++;
}
}
}catch (Exception e){
e.printStackTrace();
}
for (int index = 0; index < 200; index++) {
Person person = new Person(index+"",Datas,R.drawable.ic_launcher_background);
persons.add(person);
}
}
}
Person.java
Here this my Getter Setter class;
public class Person {
private String name;
private final String address;
private int photoId;
public Person(String name,String address, int photoId) {
this.name = name;
this.address = address;
this.photoId = photoId;
}
public int getPhotoId() {
return photoId;
}
public String getName() {
return name;
}
public String getAddress() {return address;}
}
CustomListViewAdapter.java
Here this my Adapter class;
public class CustomListViewAdapter extends ArrayAdapter<Person> {
private final LayoutInflater inflater;
private final Context context;
private ViewHolder holder;
private final ArrayList<Person> persons;
public CustomListViewAdapter(Context context, ArrayList<Person> persons) {
super(context,0, persons);
this.context = context;
this.persons = persons;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return persons.size();
}
@Override
public Person getItem(int position) {
return persons.get(position);
}
@Override
public long getItemId(int position) {
return persons.get(position).hashCode();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_view_item, null);
holder = new ViewHolder();
holder.personImage = (ImageView) convertView.findViewById(R.id.person_image);
holder.personNameLabel = (TextView) convertView.findViewById(R.id.person_name_label);
holder.personAddressLabel = (TextView) convertView.findViewById(R.id.person_address_label);
convertView.setTag(holder);
}
else{
//Get viewholder we already created
holder = (ViewHolder)convertView.getTag();
}
Person person = persons.get(position);
if(person != null){
holder.personImage.setImageResource(person.getPhotoId());
holder.personNameLabel.setText(person.getName());
holder.personAddressLabel.setText(person.getAddress());
}
return convertView;
}
//View Holder Pattern for better performance
private static class ViewHolder {
TextView personNameLabel;
TextView personAddressLabel;
ImageView personImage;
}
}
you are initializing your listview
and adapter
before you add person item in your persons ArrayList
, which means you have no item to show in your listview
in your code move fillArrayList(persons)
above initialize()