Note that there are some explanatory texts on larger screens.

plurals
  1. POMake my class take an argument
    primarykey
    data
    text
    <p>Well I have a main Screen with 5 buttons. Each time a press a button I want to go a new screen. So far I have other 5 classes (each for each screen) and 5 xmls. But Iam sure that there will be a better way beacuse this screen and the xmls are the same, and what I want to do is change some texts and some data I fetch from a database. I am sure that I can ony another class and only one xml and then pass the values that I want as arguments. (Imagine that in its final state my app must have 15 buttons, so I think it is too mych waste of space and unnecessary to have 15 .java files and 15 xml files that look the same and only some values of images and textviews change). My code for main activity is:</p> <pre><code>public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); main2Theme();} private void main2Theme() { setContentView(R.layout.main_new); Button Button100 = (Button)findViewById(R.id.Button100); Button113.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(this, OtherScreenName.class); startActivity(i); } }); //and so on for 15 buttons </code></pre> <p>My OtherScreenName.class is:</p> <pre><code>public class OtherScreenName extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Theme(); } @SuppressWarnings("null") private void Theme() { Log.d("SnowReportApp","Do first thing"); setContentView(R.layout.otherscreenname); //THIS CHANGES IN EVERY CLASS DEPENDING ON THE ID OF THE BUTTON String result = ""; InputStream is = null; StringBuilder sb=null; ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();//() before nameValuePairs.add(new BasicNameValuePair("ski_id","OtherScreenName")); TextView text1 = (TextView) findViewById(R.id.otherscreenname_1); //THESE 2 CHANGE DEPERNDING ON THE BUTTON PRESSED //perform action..... //AND ALSO HERE I NEED THE ID OF THE BUTTON b1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(OtherScreenName.this,MyActivity.class); startActivity(i); } }); </code></pre> <p>Can anyone suggest how to give arguments to my class and what it should be the type of them?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload