0

データベースからロードした後、onFetchCompleteが行の1つをリストの一番上に移動するリストビューがあります。これは機能していますが、最初の行の背景色を変更し、最初の行だけの TextView テキストと背景色も変更したいと考えています。私はアンドロイドが初めてなので、これを理解するのに苦労しています。いくつかの助けをいただければ幸いです。

1行を変更する場所は次のとおりです。

@Override
public void onFetchComplete(List<Application> data) {
    String myDefault = "3";
    // dismiss the progress dialog
    if(dialog != null)  dialog.dismiss();
    // create new adapter
    ApplicationAdapter adapter = new ApplicationAdapter(this, data);

    for(int i = 0; i < data.size(); ++i){
        if(data.get(i).getAppID().equals(myDefault)){
            Application app = data.get(i);
            data.remove(i);
            data.add(0, app);
        }
    }


    // set the adapter to list
    setListAdapter(adapter);
}

ListView が最初に読み込まれるときにビューを取得していくつかの変更を加えようとしましたが、これを行うと最初と最後の行が変更されます。なぜこれを行うのかわかりません。また、行全体の背景を変更する方法がわかりません。

これが私が試したことの例です:

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if(v == null) {
        LayoutInflater li = LayoutInflater.from(getContext());
        v = li.inflate(R.layout.app_custom_list, null);            
    }

    Application app = items.get(position);

    if(app != null) {
        ImageView icon = (ImageView)v.findViewById(R.id.iconImg);
        TextView titleText = (TextView)v.findViewById(R.id.titleTxt);
        TextView descText = (TextView)v.findViewById(R.id.descTxt);            
        TextView creatorText = (TextView)v.findViewById(R.id.creatorTxt);
        TextView createdText = (TextView)v.findViewById(R.id.createdTxt);            
        TextView rankText = (TextView)v.findViewById(R.id.rankTxt);

        if(icon != null) {
            Resources res = getContext().getResources();
            String sIcon = "com.sj.jsondemo:drawable/" + app.getIcon();
            icon.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
        }

        if(position==0)
        {
            if(titleText != null) {
                titleText.setText(app.getTitle());
                titleText.setBackgroundColor(Color.parseColor("#E4D0C6"));
            }
            if(descText != null) descText.setText(app.getDesc());
            if(creatorText != null) creatorText.setText(app.getCreator());            
            if(createdText != null) createdText.setText(app.getCreated());            
            if(rankText != null) rankText.setText(app.getRank()); 
        }
        else
        {
            if(titleText != null) titleText.setText(app.getTitle());
            if(descText != null) descText.setText(app.getDesc());
            if(creatorText != null) creatorText.setText(app.getCreator());            
            if(createdText != null) createdText.setText(app.getCreated());            
            if(rankText != null) rankText.setText(app.getRank());                   
        }


    }

    return v;
}
4

0 に答える 0