public class Great_listviewActivity extends Activity {
EditText edittext;
ListView listview;
Button search;
String[] text = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
int[] image = { R.drawable.icon, R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon };
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
search = (Button) findViewById(R.id.Button01);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setAdapter((ListAdapter) new MyCustomAdapter(text, image));
search.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
textlength = edittext.getText().length();
text_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++)
{
if (textlength <= text[i].length())
{
if (edittext.getText().toString().equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
{
text_sort.add(text[i]);
image_sort.add(image[i]); } }
} //end of for loop
listview.setAdapter(new MyCustomAdapter(text_sort, image_sort));
} //end of onClick
}); //end of search click
}
class MyCustomAdapter extends BaseAdapter implements ListAdapter
{
String[] data_text;
int[] data_image;
MyCustomAdapter()
{
}
MyCustomAdapter(String[] text, int[] image)
{
data_text = text;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<Integer> image)
{
data_text = new String[text.size()];
data_image = new int[image.size()];
for (int i = 0; i < text.size(); i++) {
data_text[i] = text.get(i);
data_image[i] = image.get(i);
}
}
public int getCount()
{
return data_text.length;}
public String getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview, parent, false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
ImageView imageview = (ImageView) row.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
imageview.setImageResource(data_image[position]);
return (row);
}
그것은 라인 listview.setAdapter ((ListAdapter) 새로운 MyCustomAdapter (텍스트, 이미지))에서 난처하게되었다; 단지 소스가 발견되지 않는다고 말합니다. 그것은 틀릴 수있는 것에 대한 단서를 남기지 않습니다.다음 안드로이드 코드를 디버깅
추측하는 것은 이클립스 오류입니다 ... 아마도 이것을 보길 원할 것입니다 : http://stackoverflow.com/questions/6174550/eclipse-java-debugging-source-not-found – Matthieu
@lilzz 당신은 저에게 말할 수 있습니까? 오류가 무엇입니까? –
레이아웃 목록보기를 게시 할 수 있습니까? – antonio081014