Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Posting my comment as an answer, requested by OP to clear it up></p> <p>You <strong>really</strong> should not use a single <code>String[]</code> to hold semantically different kinds of data together! </p> <p>The first element is a <em>classname</em>, the second is a <em>label</em> semantic: you should have a signature for this method having them separate! The single array is ureadable, unstructured, generally unmaintainable!</p> <p>(I also added a condition to check for null in classNAme here... I assume having className as null is a fatal error.)</p> <pre><code>private void addBookmark(String labelText, String className) { //check className not to be null if(className==null) { //handle error somehow, log error, etc ... //no point in doing anything the listener, it would not do any good, just return return; } LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.single_bookmark, null); TextView text = (TextView) v.findViewById(R.id.bookmark_text); Button button = (Button) v.findViewById(R.id.bookmark_button); text.setText(labelValue); // variable "labelValue" final String myClass = className; //variable className //checking for null button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Class&lt;?&gt; cl = null; try { cl = Class.forName(myClass); } catch (ClassNotFoundException e) { e.printStackTrace(); //this case should be handled better. } Intent myIntent = new Intent(mContext, cl); startActivity(myIntent); } }); </code></pre> <p>Of course, when you call this method, you should also change the code from:</p> <pre><code>addBookmark(anArrayOfStrings); </code></pre> <p>To</p> <pre><code>addBookmark(myLabelValueString, myClassNameString); </code></pre> <p>Where myLabelValueString, myClassNameString are String variables containing the respective values.</p>
 

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