我有一个数组列表,我想把它放入一个私人字符串,然后通过电子邮件或whatsapp发送它 这些是我使用的代码 第一项活动
b1=(Button) findViewById(R.id.btnsMu);
b1.setOnClickListener( new View.OnClickListener() {
@SuppressLint("WrongConstant")
@Override
public void onClick(View view) {
SharedPreferences sharedPreferences = getSharedPreferences( "mushroom",Context.MODE_PRIVATE );
SharedPreferences.Editor editor = sharedPreferences.edit();
textMu = "";
textMu += "(" + quantity1 + ")" + " " + getString( R.string.mushroom_string );
priceMu = quantity1 * 500 ;
editor.putString( "mushroomS", textMu );
editor.putInt( "mushroomI", priceMu );
editor.commit();
finish();
}
});
arrayList里面的第二个活动
ListView lv;
ArrayList<Word> volues;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_order );
SharedPreferences mushroom = getSharedPreferences( "mushroom",Context.MODE_PRIVATE );
mushroomS = mushroom.getString( "mushroomS","" );
volues = new ArrayList<Word>( );
if (TextUtils.isEmpty( mushroomS )){
volues.remove( mushroomS );
}
else {
volues.add( new Word( mushroomS ) );
}
WordAdapter adapter = new WordAdapter( this, volues, R.layout.row_item );
lv = (ListView) findViewById(R.id.list_view);
lv.setAdapter(adapter);
ImageView img = (ImageView) findViewById( R.id.whatsapp );
Bitmap btmp = BitmapFactory.decodeResource( getResources(),R.drawable.whatsapp );
RoundedBitmapDrawable rounbtmp = RoundedBitmapDrawableFactory.create( getResources(),btmp );
rounbtmp.setCircular( true );
img.setImageDrawable( rounbtmp );
img.setClickable( true );
img.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = nam.getText().toString();
String add = address.getText().toString();
String phonNu = phon.getText().toString();
String comment = comments.getText().toString() ;
String priceMessages = createOrderSummary( calculatePrice2(),add,name,phonNu,comment,allText() );
String toNumber = "+963 95602 2179"; // contains spaces.
toNumber = toNumber.replace( "+","" ).replace( " ","" );
Intent sendIntent = new Intent( "android.intent.action.MAIN" );
sendIntent.putExtra( "jid",toNumber + "@s.whatsapp.net" );
sendIntent.putExtra( Intent.EXTRA_TEXT,priceMessages );
sendIntent.setAction( Intent.ACTION_SEND );
sendIntent.setPackage( "com.whatsapp" );
sendIntent.setType( "text/plain" );
startActivity( sendIntent );
}
} );
private String createOrderSummary(int total,String address,String name,String phonNu,String comments,String allText) {
String priceMessage = getString( R.string.name ) + name;
priceMessage += "\n" + getString( R.string.address_1 ) + address;
priceMessage += "\n" + getString( R.string.phone_1 ) + phonNu;
priceMessage += "\n" + getString( R.string.submit_order_comments ) + comments ;
priceMessage += "\n" + getString( R.string.the_order_1 );
priceMessage += "\n" + allText;
priceMessage += "\n" + getString( R.string.total_1 ) + total;
priceMessage += "\n" + getString( R.string.thank_you );
return priceMessage;
}
//This is to convert the arrayList into a private string and place it within another string
private String allText(){
String string = "";
string += volues;
return string;
}
但结果并不令人满意。数组出现在消息文本符号中,如图所示难以理解 但是我想让它显示数组中的数据 用户应该具有包含他已预订的内容的表达式,例如 Primo鸡肉(2) 热狗披萨(1) 当你通过电子邮件或whatsapp发送时,我只是在屏幕上的arrayList结果有问题。 当应用程序内部的屏幕上的arrayList的结果处于良好状态并且成功时 enter image description here