I have CustomAdapter which extends ArrayAdapter. Constructor is called properly also data for ArrayList contains 20 items. But my getView() method is not called at all. I dont understand what is wrong. Here is my code. There are two getViev() methods commented original and simplified test getView(). Non them are called:
package web.php5.learn2codelist;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import java.util.ArrayList;
public class CustomListAdapter extends ArrayAdapter<String>
{
Context context;
ArrayList<String> data;
public CustomListAdapter(@NonNull Context context, ArrayList<String> data)
{
super(context, R.layout.row);
this.context = context;
this.data = data;
Log.d("111", "count: " + String.valueOf(data.size())); // 20 items
Log.d("111", "getView: 11111111111111111111111111111"); // Log is ok
}
@Override @NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
Log.d("222", "getView: 2222222222222222222222222222222"); // No log
return convertView;
}
/*@Override
public @NonNull View getView(final int position, View convertView, @NonNull ViewGroup parent) // final umoznuje pouzit tuto premennu v onClick
{
Log.d("333", "getView: 33333333333333333333333333333333"); // No log
View row = convertView;
Log.d("TAG1", "row: " + String.valueOf(row));
if( row == null )
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row, parent, false);
}
TextView label = row.findViewById(R.id.row_label);
Button btn = row.findViewById(R.id.row_button);
label.setText(data.get(position));
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
data.remove(position);
notifyDataSetChanged();
}
});
return row;
}*/
}