-1

学習目的でフッターメニューの簡単なAndroidプログラムを作成しました。フッターの4つのメニューのいずれかを選択すると、選択したメニュー画像を変更する必要があります。以下のように試しましたが、機能しません。同様にそれをチェックしてください:ここに画像の説明を入力

コードは次のとおりです。

menu.java p

ackage com.esp.therisemethod.uc;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.esp.therisemethod.R;
import com.esp.therisemethod.ui.ContactusActivity;
import com.esp.therisemethod.ui.InfoActivity;
import com.esp.therisemethod.ui.ProgressActivity;
import com.esp.therisemethod.ui.ProgressGraph;

public class Menu extends RelativeLayout implements OnClickListener {

    public LinearLayout llfooterHome;
    public LinearLayout llfooterGraph = null;
    public LinearLayout llfooterInfo = null;
    public LinearLayout llfooterContactUs = null;
    public Context objContext;

    public Menu(Context context) {
        super(context);
        objContext = context;
        init();
    }

    public Menu(final Context context, AttributeSet attrs) {
        super(context, attrs);
        objContext = context;
        init();
    }

    public void init() {
        View view = LayoutInflater.from(objContext).inflate(R.layout.uc_menu,
                this, true);

        llfooterHome = (LinearLayout)view.findViewById(R.id.llfooterHome);
        llfooterGraph = (LinearLayout) view.findViewById(R.id.llfooterGraph);
        llfooterInfo = (LinearLayout) view
                .findViewById(R.id.llfooterInfo);
        llfooterContactUs = (LinearLayout) view
                .findViewById(R.id.llfooterContactUs);

        llfooterGraph.setOnClickListener(this);
        llfooterInfo.setOnClickListener(this);
        llfooterContactUs.setOnClickListener(this);
        llfooterHome.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
        case R.id.llfooterHome:

            intent = new Intent(objContext, ProgressActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            objContext.startActivity(intent);
            break;
        case R.id.llfooterGraph:
            intent = new Intent(objContext, ProgressGraph.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            objContext.startActivity(intent);
            break;
        case R.id.llfooterInfo:
            intent = new Intent(objContext, InfoActivity.class);
            objContext.startActivity(intent);

            break;
        case R.id.llfooterContactUs:
            intent = new Intent(objContext, ContactusActivity.class);
            objContext.startActivity(intent);

            break;
        }

    }

    public void setSelectedTab(int selectTab) {
        switch (selectTab) {
        case 1:
            llfooterHome.setBackgroundResource(R.drawable.home_active);

            llfooterGraph.setBackgroundResource(R.drawable.graph_default);
            llfooterInfo.setBackgroundResource(R.drawable.info_default);
            llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);
            break;
        case 2:
            llfooterHome.setBackgroundResource(R.drawable.home_default);

            llfooterGraph.setBackgroundResource(R.drawable.graph_active);
            llfooterInfo.setBackgroundResource(R.drawable.info_default);
            llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);

            break;
        case 3:
            llfooterHome.setBackgroundResource(R.drawable.home_default);

            llfooterGraph.setBackgroundResource(R.drawable.graph_default);
            llfooterInfo.setBackgroundResource(R.drawable.info_active);
            llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);
            break;

        case 4:
            llfooterHome.setBackgroundResource(R.drawable.home_default);

            llfooterGraph.setBackgroundResource(R.drawable.graph_default);
            llfooterInfo.setBackgroundResource(R.drawable.info_default);
            llfooterContactUs.setBackgroundResource(R.drawable.contactus_active);
            break;
        }
    }

}
4

1 に答える 1

0

このコードは私のために働いた、

switch (v.getId()) {
        case R.id.llfooterHome:

            intent = new Intent(objContext, ProgressActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            objContext.startActivity(intent);
            break;
        case R.id.llfooterGraph:
            intent = new Intent(objContext, ProgressGraph.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            objContext.startActivity(intent);
            break;
        case R.id.llfooterInfo:
            intent = new Intent(objContext, InfoActivity.class);
            objContext.startActivity(intent);

            break;
        case R.id.llfooterContactUs:
            intent = new Intent(objContext, ContactusActivity.class);
            objContext.startActivity(intent);

            break;
        }
于 2013-06-27T12:53:01.470 に答える