2013-09-05 4 views
1

저는 Android 프로그래밍이 처음인데 입력 데이터를 가져 와서 전화에 저장 한 다음 이메일을 통해 전송하는 앱을 만들려고합니다. 나는 curently 붙어있어. 내 앱에는 현재 저장하지 않는 입력과 텍스트 문자열을 가져 와서 텍스트 메시지의 텍스트로 저장할 수있는 공유 버튼이 있습니다. 그것은 내가 지금까지 알아 낸 모든 것입니다.editText를 shareIntent로 출력하려고합니다.

지금 내 질문은 : 입력 (editText1)에서 텍스트를 가져 와서 공유 기능의 일반 텍스트로 설정하려면 어떻게해야합니까?

나는 온라인에서 보았던 많은 것들을 시도해 보았고 오류가 발생할 수있는 동안 실제로 앱을 열 때 목록 항목을 열면 충돌이 발생하거나 중지됩니다.

package com.example.nextslidemenuapp; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.NavUtils; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.EditText; 


public class ItemDetailActivity extends FragmentActivity { 

protected String mString; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_item_detail); 

    // Show the Up button in the action bar. 
    getActionBar().setDisplayHomeAsUpEnabled(true); 

    // savedInstanceState is non-null when there is fragment state 
    // saved from previous configurations of this activity 
    // (e.g. when rotating the screen from portrait to landscape). 
    // In this case, the fragment will automatically be re-added 
    // to its container so we don't need to manually add it. 
    // For more information, see the Fragments API guide at: 
    // 
    // http://developer.android.com/guide/components/fragments.html 
    // 
    if (savedInstanceState == null) { 
     // Create the detail fragment and add it to the activity 
     // using a fragment transaction. 
     Bundle arguments = new Bundle(); 
     arguments.putString(ItemDetailFragment.ARG_ITEM_ID, getIntent() 
       .getStringExtra(ItemDetailFragment.ARG_ITEM_ID)); 
     ItemDetailFragment fragment = new ItemDetailFragment(); 
     fragment.setArguments(arguments); 
     getSupportFragmentManager().beginTransaction() 
       .add(R.id.item_detail_container, fragment).commit(); 
    } 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu, menu); 
    return true; 
} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int itemId = item.getItemId(); 

    if (itemId == R.id.action_share) { 
     sharePost(); 
    } 

    if (itemId == android.R.id.home) { 
     // This ID represents the Home or Up button. In the case of this 
     // activity, the Up button is shown. Use NavUtils to allow users 
     // to navigate up one level in the application structure. For 
     // more details, see the Navigation pattern on Android Design: 
     // 
     // http://developer.android.com/design/patterns/navigation.html#up-vs-back 
     // 
     NavUtils.navigateUpTo(this, 
       new Intent(this, ItemListActivity.class)); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 
final EditText ed1 = (EditText) findViewById(R.id.editText1); 

String myString = "text"; 

private void sharePost() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, myString); 
    startActivity(Intent.createChooser(shareIntent,  
getString(R.string.share_chooser_title))); 

} 
} 

을 그리고 여기에 내가 편집에 초점을 맞추고있어 특정 코드입니다 :

final EditText ed1 = (EditText) findViewById(R.id.editText1); 

String myString = "text"; 

private void sharePost() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, myString); 
    startActivity(Intent.createChooser(shareIntent, 
getString(R.string.share_chooser_title))); 

} 

나는 코드 "텍스트"를 대체하기 위해 노력하고있어

여기에 작동 내 조각 코드입니다 editText1을 가져옵니다. 결국 나는 여러 개의 입력 상자를 세미콜론으로 연결하려고한다.

도움 주셔서 감사합니다.

+0

'ed1.getText()'메소드를 호출하고 싶습니다. http://developer.android.com/reference/android/widget/EditText.html#getText() – Android2390

+0

editable을 String으로 변환 할 수 없다는 오류가 발생합니다. – user2752165

+0

.toString () 결국. 전체 줄은'ed1.getText(). toString()'이어야합니다. – Android2390

답변

0

좋아 여기에 솔루션을 게시하려고 :

EditText ed1; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_item_detail); 

ed1 = (EditText) findViewById(R.id.editText1); 
} 

private void sharePost() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, ed1.getText().toString()); 
    startActivity(Intent.createChooser(shareIntent, 
    getString(R.string.share_chooser_title))); 
} 

이 귀하의 질문은 여전히 ​​매우 모호으로 최종 해결책이 아니다. 그러나 이것이 어떻게 보일 것인가입니다. 결론 : editText를 인스턴스화하고, editText에서 데이터를 가져 와서 shareIntent를 통해 해당 텍스트를 공유합니다.

+0

거의 효과가있어, 목록 항목에 들어가서 입력란을 채울 수 있지만 공유를 클릭하면 나에게 "앱이 있습니다. 중지됨 "오류가 다시 나타납니다. 너무 가까이! – user2752165

관련 문제