0

リストアクティビティのレイアウトに問題があります。私のリストには区切り文字とテキスト行が含まれています

SetupActivityはListActivityを拡張します

private MyCustomAdapter mAdapter;
TextView selection;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    mAdapter = new MyCustomAdapter();

    mAdapter.addItem("Help/FAQ");
    mAdapter.addSeparatorItem("Connection to Server");
    // mAdapter.addItem("Connection");
    // mAdapter.addItem("Network");
    // mAdapter.addItem("config");
    // mAdapter.addItem("User");
    // mAdapter.addItem("pass");
    // mAdapter.addItem("Email");
    // mAdapter.addItem("PlatForm");
    mAdapter.addSeparatorItem("Consumption");
    // mAdapter.addItem("100%");
    mAdapter.addSeparatorItem("Map");
    // mAdapter.addItem("Map rotation");
    // mAdapter.addItem("auto Zoom");
    // mAdapter.addItem("Measure Units");
    // mAdapter.addItem("Show Heading");
    // mAdapter.addItem("Compass North");*/
    mAdapter.addFooterItem(getString(R.string.setup_note_map));
    mAdapter.addSeparatorItem("Support");
    mAdapter.addItem("About");
    /*
     * mAdapter.addItem("Contact Us"); mAdapter.addItem("Tutorial");
     * mAdapter.addItem("Setup Wizard");
     */
    mAdapter.addSeparatorItem("Blogs");
    mAdapter.addFooterItem(getString(R.string.setup_note_blogs));

    setListAdapter(mAdapter);

    // selection = (TextView) findViewById(R.id.text);
}

public void onListItemClick(ListView parent, View view, int position,
        long id) {
    parent.getChildAt(position).setBackgroundColor(position);
    if (position == 0) {
        Intent myIntent = new Intent(SetupActivity.this,
                WebviewHandlerActivity.class);
        myIntent.putExtra("ressource", "help");
        SetupActivity.this.startActivity(myIntent);
    } else if (position == 6) {
        Intent myIntent = new Intent(SetupActivity.this,
                AboutActivity.class);
        SetupActivity.this.startActivity(myIntent);
    }

}

// Adapter Class
private class MyCustomAdapter extends BaseAdapter {

    private static final int TYPE_ITEM = 2;
    private static final int TYPE_SEPARATOR = 0;
    private static final int TYPE_FOOTER = 1;
    private static final int TYPE_MAX_COUNT = TYPE_ITEM + 1;

    private ArrayList<String> mData = new ArrayList<String>();
    private LayoutInflater mInflater;

    private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();

    private TreeSet<Integer> mFooterSet = new TreeSet<Integer>();

    public MyCustomAdapter() {
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void addItem(final String item) {
        mData.add(item);
        notifyDataSetChanged();
    }

    public void addSeparatorItem(final String item) {
        mData.add(item);
        // save separator position
        mSeparatorsSet.add(mData.size() - 1);
        notifyDataSetChanged();
    }

    public void addFooterItem(final String item) {
        mData.add(item);
        // save separator position
        mFooterSet.add(mData.size() - 1);
        notifyDataSetChanged();
    }

    @Override
    public int getItemViewType(int position) {
        if (mSeparatorsSet.contains(position))
            return TYPE_SEPARATOR;
        else if (mFooterSet.contains(position))
            return TYPE_FOOTER;
        return TYPE_ITEM;
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_MAX_COUNT;
    }

    public int getCount() {
        return mData.size();
    }

    public String getItem(int position) {
        return mData.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        int type = getItemViewType(position);
        if (convertView == null) {
            holder = new ViewHolder();
            switch (type) {
            case TYPE_ITEM:
                convertView = mInflater.inflate(R.layout.item1, null);
                holder.textView = (TextView) convertView
                        .findViewById(R.id.text);
                break;
            case TYPE_SEPARATOR:
                convertView = mInflater.inflate(R.layout.item2, null);
                holder.textView = (TextView) convertView
                        .findViewById(R.id.textSeparator);
                break;
            case TYPE_FOOTER:
                convertView = mInflater.inflate(R.layout.footer, null);
                holder.textView = (TextView) convertView
                        .findViewById(R.id.note);
                break;
            }
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(mData.get(position));
        return convertView;
    }

}

public static class ViewHolder {
    public TextView textView;
}

私のxmlには、内部にitem1 & item2が含まれています。LinearLayoutTextViewfooter.xmltextView

私の問題は、行をクリックしても、フッター以外はクリックしたと言ってもオレンジ色にならないことです...(不要なもの)

だから私はそれが入っていないからだと思いますLinearLayoutので、私はのを延期しようとしましたLinearLayoutitem1.xml、私はもうコンパイルできません。

誰かが私のフッターではなく、[アニメーション]をクリックして私の行を取得する方法を説明できますか?

乾杯

4

1 に答える 1

0

You are not getting clicked color because you have set a background color `

setBackgroundColor

You need to set a statelistDrawable as background

Edit: You need to set a drwable something like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/pressed_img" android:state_pressed="true"/>
    <item android:drawable="@drawable/default_img"/>   
</selector>
于 2012-08-17T14:54:16.940 に答える