0

メインアクティビティにリストビューがあります。各行に画像ビューがあります。その画像ビューをクリックすると、クイックアクション(iOSのポップオーバーのようなもの)が表示されます。私の要求は、リストビューから別のアクティビティにテキストを設定したいです。クイック アクションでアクション アイテムをクリックするとテキストを編集します。助けてください。

ここに私の主な活動があります

public class ExampleActivity extends Activity {

private static final int ID_UP = 1;
private static final int ID_DOWN = 2;
private static final int ID_SEARCH = 3;
private static final int ID_INFO = 4;

private QuickAction quickAction;
private ActionItem nextItem;
private ActionItem prevItem;
private ActionItem searchItem;

private ListView view;
private ContactsAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    view = (ListView) findViewById(R.id.listView1);
    final Weather weather_data[] = new Weather[] { new Weather(R.drawable.icon, "Cloudy"),
            new Weather(R.drawable.icon, "Showers"),
            new Weather(R.drawable.icon, "Snow"),
            new Weather(R.drawable.icon, "Storm"),
            new Weather(R.drawable.icon, "Sunny")

    };
    adapter = new ContactsAdapter(this, R.layout.main1,
            weather_data);          
}


void functiontorun(View view1) {
     quickAction = new QuickAction(this,QuickAction.HORIZONTAL);
    nextItem = new ActionItem(ID_DOWN, "Next", getResources().getDrawable(
            R.drawable.menu_down_arrow));
    prevItem = new ActionItem(ID_UP, "Prev", getResources().getDrawable(
            R.drawable.menu_up_arrow));
    searchItem = new ActionItem(ID_SEARCH, "Find", getResources()
            .getDrawable(R.drawable.menu_search));

    // use setSticky(true) to disable QuickAction dialog being dismissed
    // after an item is clicked
    prevItem.setSticky(true);
    nextItem.setSticky(true);

    // add action items into QuickAction
    quickAction.addActionItem(nextItem);
    quickAction.addActionItem(prevItem);
    quickAction.addActionItem(searchItem);
    // Set listener for action item clicked
     final int position1 = view.getPositionForView(view1);

    quickAction
            .setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
                @Override
                public void onItemClick(QuickAction source, int pos,
                        int actionId) {
                    ActionItem actionItem = quickAction.getActionItem(pos);

                    if (actionId == ID_SEARCH) {
            Intent i=new Intent(ExampleActivity.this,Second.class);
                        i.putExtra("position",position1 );
                        Log.v("position","po" +position1);
                        startActivity(i);

                    } else if (actionId == ID_INFO) {
                        Toast.makeText(getApplicationContext(),
                                "I have no info this time",
                                Toast.LENGTH_SHORT).show();

                    } else {
                        Toast.makeText(getApplicationContext(),
                                actionItem.getTitle() + " selected",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

     quickAction.show(view1);

}

}

そして私のもう一つの活動

public class Second extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);
    EditText d1=(EditText) findViewById(R.id.editText1);
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        final int position = (Integer) bundle.get("position");
        Log.v("position","po1  " +position);
        ArrayList<Weather> array = new ArrayList<Weather>();
        Log.v("position","po1  " +array);

    }
}

}

連絡先アダプター:

public class ContactsAdapter extends ArrayAdapter{

    Context context; 
    int layoutResourceId;    
    Weather data[] = null;
    public ContactsAdapter(Context context, int layoutResourceId, Weather[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        WeatherHolder holder = null;

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new WeatherHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.imageView1);
            holder.imgIcon.findViewById(R.id.imageView1).setOnClickListener(mBuyButtonClickListener);
            holder.txtTitle = (TextView)row.findViewById(R.id.textView1);
            //((ImageView) row.findViewById(R.id.im)).setOnClickListener(mBuyButtonClickListener);
            row.setTag(holder);
        }
        else
        {
            holder = (WeatherHolder)row.getTag();
        }

        Weather weather = data[position];
        holder.txtTitle.setText(weather.title);
        holder.imgIcon.setImageResource(weather.icon);
        return row;
    }

    static class WeatherHolder
    {
        ImageView imgIcon;
        TextView txtTitle;
    }
    private OnClickListener mBuyButtonClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((ExampleActivity) context).functiontorun(v);
        }
    };

}
4

1 に答える 1

0
    private OnClickListener mBuyButtonClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
          WeatherHolder  holder = (WeatherHolder) v.getTag;
          String string =  holder.txtTitle .getText();

        ((ExampleActivity) context).functiontorun(string);
    }
};

文字列をアクティビティに渡し、関数のパラメータを変更して文字列として実行するだけです

于 2013-03-22T08:13:51.570 に答える