|
package net.origami.android.examples;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class CustomAdapterConverterView extends BaseAdapter {
private final String[] _items;
private final LayoutInflater _inflater;
public CustomAdapterConverterView(Context context, String... items) {
_inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
_items = items;
}
@Override
public int getCount() {
return _items.length;
}
@Override
public Object getItem(int position) {
return _items[position];
}
@Override
public long getItemId(int position) {
return position + 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// 1.
if (convertView == null) {
convertView = _inflater.inflate(R.layout.item, null);
}
// 2.
TextView positionText = (TextView) convertView
.findViewById(R.id.position);
TextView idText = (TextView) convertView.findViewById(R.id.id);
TextView itemText = (TextView) convertView.findViewById(R.id.item);
// 3.
positionText.setText("position: " + position);
idText.setText("id: " + getItemId(position));
itemText.setText("item: " + getItem(position));
return convertView;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.