2011-11-03 6 views
0
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(テキスト、画像))にアップつまずいてしまいました。それは単にソースが見つかりません。何が間違っているのか分かりません。次のAndroidのコードをデバッグ

+0

これはEclipseエラーです...これを見てみてください:http://stackoverflow.com/questions/6174550/eclipse-java-debugging-source-not-found – Matthieu

+0

@lilzzあなたは私に教えてくれますか?エラーは何ですか? –

+0

レイアウトリストビューを投稿できますか? – antonio081014

答えて

0

それはちょうどソースこれはあなたにこのサイトにそのメッセージを検索するための手がかりを与えてくれたことができ

を見つけていないと言います。 this questionへの回答をご覧ください。何が起きているのかを理解するのに役立ちます。

0

正しいJavaコンパイラがEclipse環境に接続されているかどうかを確認しましたか。

関連する問題