2013-04-16 58 views
-4

我有1 TextView & Button在1屏幕和ListView在另一個屏幕上,我想發送數據到按鈕單擊列表視圖。 那麼怎麼可能,是否有必要採取數據庫或數組是可能的? 以下是我所做的代碼。TextView到列表視圖數據顯示在android

MainActivity.java

public class MainActivity extends Activity { 
TextView tx ; 
int tv; 
int counter = 0; 
String[] planets; 

private ArrayList<String> mArray; 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    planets = getResources().getStringArray(R.array.Jokes_array); 

    //final Button button = (Button) findViewById(R.id.button11); 

    tx = (TextView)findViewById(R.id.textViewapp1);  
    tx.setText(planets[counter]); 


    Button button = (Button)findViewById(R.id.btnsms); 
    Button btnFavr = (Button)findViewById(R.id.btnfav); 

    button.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      //startActivity(new Intent(IcontrolActivity.this,Settings.class)); 
      /*    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
      sharingIntent.setType("text/plain"); 
      //String shareBody = (String) getText(R.id.textViewapp1); 
      sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here"); 
      sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); 
      startActivity(Intent.createChooser(sharingIntent, "Share via"));*/ 

      Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
      sharingIntent.putExtra(Intent.EXTRA_TEXT, ((TextView) findViewById(R.id.textViewapp1)).getText()); 
      sharingIntent.setType("text/plain"); 
      startActivity(sharingIntent); 



      // TODO Auto-generated method stub 

     } 
    }); 

    btnFavr.setOnClickListener(new View.OnClickListener() { 


     public void onClick(View v) { 

      // TODO Auto-generated method stub 
      Toast toast = Toast.makeText(MainActivity.this, R.string.messageWordAddedToFarvourite, Toast.LENGTH_SHORT); 
      toast.show(); 
      /* SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); 
       editor.putString(tx,getString(R.id.textViewapp1)); 
       editor.commit();*/ 
      //ArrayList<String> arryList = new ArrayList<String>(); 
      mArray.add(tx.getText().toString());    

     } 
    }); 

    btnFavr.setOnLongClickListener(new View.OnLongClickListener() { 

     @Override 
     public boolean onLongClick(View v) { 

      Intent intent = new Intent(getApplicationContext(), FavActivity.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          getApplicationContext().startActivity(intent); 

      return false; 
     } 
    }); 
} 

也有上我的工作,這將顯示在其中保存在單擊事件和長點擊它會顯示ListView控件文件列表視圖內容另一個Java文件。

+3

給我們看一些代碼.. – Raghunandan

+0

強烈建議在提出問題之前展示一些努力。所以下次小心你這樣做。回答你的問題:不,數據庫不是必需的,你可以簡單地使用ArrayList並傳遞數據。 –

回答

0

使用arrayadpater與列表視圖和調用arrayadpater.notifyondatachange()mtd按鈕單擊其中您將數據添加到arraylist。

相關問題