I am trying to make a read aloud menu option here. This is the code I have written. But it doesn't really read aloud the text on the card. The doc says that if there is any text set on the card it will read aloud. My card has some text on it :
newcard.setText("text");
My MenuActivity
which is called looks like this.
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MenuActivity extends Activity {
public Object json(int menuid)
{
JSONObject obj = new JSONObject();
try {
System.out.println("goes into try of json");
obj.put("text", "Hello World");
obj.put("menuItems", new JSONObject().put("action", "READ_ALOUD"));
System.out.println(obj);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return obj;
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
openOptionsMenu();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.read_aloud_menu_item:
System.out.println("goes itno read aloud case");
json(item.getItemId());
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onOptionsMenuClosed(Menu menu) {
// Nothing else to do, closing the activity.
finish();
}
}
I am really not sure wheteher I can pass the JSON like this. If not like this, how else can I do this?