我對編程非常陌生。我有一個有幾個視圖的應用程序。主視圖顯示了一份清單,如早餐,午餐&晚餐。當選擇一個項目時,例如午餐,會顯示午餐菜單項目列表,如漢堡包,芝士漢堡,薯條......(該列表是從存儲在\ values \ lunch.xml中的字符串數組lunch_menu創建的)當用戶選擇他們想要的項目時,它被存儲在一個名爲myNewList的新數組中,並且當用戶按下lunchList按鈕時被顯示。顯示用戶選擇的所有項目。到現在爲止還挺好。我在selecteditems.xml中創建了一個android:onClick =「shareMyList」,該按鈕可以工作,但不會填充我的列表。我想我需要的是如何將其轉換爲字符串,這是我需要幫助的地方。通過消息應用程序發送ListView結果
這是我的問題現在....我有我的共享按鈕,當按下時,我想它會自動打開默認的消息應用程序,並從選定的項目ListView填充列表。
package com.mycompany.lunch;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class LunchListMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maincoarse);
final ListView lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, R.array.lunch_menu,android.R.layout.simple_list_item_1);
lv.setAdapter(adapter);
final ArrayList<String> myNewList = new ArrayList<String>();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String item=lv.getItemAtPosition(arg2).toString();
String itemordered;
itemordered = item + " added to list";
Toast.makeText(getApplicationContext(), itemordered, Toast.LENGTH_SHORT).show();
myNewList.add(item);
}
});
// List View Button
Button btnLunchList = (Button) findViewById(R.id.lrList);
btnLunchList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.selecteditems);
ListView selecteditems = (ListView) findViewById(android.R.id.list);
ArrayAdapter<String> newadapter = new ArrayAdapter<String>(LunchListMenu.this, android.R.layout.simple_list_item_1, myNewList);
selecteditems.setAdapter(newadapter);
}
});
}
public void shareMyList(View v){
// Share Selected Items Button
Button btnShareItems = (Button) findViewById(R.id.shareMyList);
btnShareItems.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
startActivity(Intent.createChooser(share, "Share Text"));
}
});
}
}
這裏的午餐菜單佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/main_background"
android:paddingLeft="10.0dip"
android:paddingTop="0.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/lrList"
android:layout_width="72dip"
android:layout_height="72dip"
android:layout_gravity="right"
android:background="@drawable/list" />
<ImageView
android:id="@+id/LunchMenuTitle"
android:contentDescription="@string/LunchMenu"
android:layout_width="0dip"
android:layout_height="72dip"
android:layout_weight="0.96"
android:background="@drawable/lunch"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="10.0dip"
android:background="@drawable/head"
android:orientation="horizontal" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#FFCC00"
android:dividerHeight="2dp" >
</ListView>
<LinearLayout
android:orientation="horizontal"
android:background="@drawable/head"
android:layout_width="fill_parent"
android:layout_height="10.0dip" />
</LinearLayout>
,這裏是我的selecteditems.xml佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/main_background"
android:paddingLeft="10.0dip"
android:paddingTop="0.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/shareMyList"
android:layout_width="72dip"
android:layout_height="72dip"
android:layout_gravity="right"
android:onClick="shareMyList"
android:background="@drawable/share" />
<ImageView
android:id="@+id/selectedItemsTitle"
android:contentDescription="@string/LunchTitle"
android:layout_width="0dip"
android:layout_height="72dip"
android:layout_weight="0.96"
android:background="@drawable/title"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="10.0dip"
android:background="@drawable/head"
android:orientation="horizontal" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#FFCC00"
android:dividerHeight="2dp"
android:padding="10dip"
android:textColor="#ffffff"
android:textSize="20dip"
android:textStyle="bold" />
</LinearLayout>
沒有人有任何線索? – Sobo 2012-07-27 22:52:07