Hide first item in the spinner - spinner

I working on the spinner , there are 5 items in the spinner , i just want to hide the first item in the spinner , not to remove ,just hide.Problem is that when i click on the spinner ,without selecting an item the api get hit by using first item_id , i just added the blank feild in the spinner at first position(0). it is working properly .Only issue is that the visibility of the first blank item.I want to hide that item. My code is as follows :
JSONArray staff_array;
List<String> owner_list =new ArrayList<String>();
final List<String> owner_id_list = new ArrayList<String>();
try
{
isEnabled(0); //To disable First Item
owner_list.add("");
owner_id_list.add("");
for (int i = 0; i <staff_array.length(); i++)
{
JSONObject staff_obj=staff_array.getJSONObject(i);
String fname=staff_obj.getString(FIRST_NAME);
String lname=staff_obj.getString(LAST_NAME);
owner_id_list.add(staff_obj.getString(STAFF_ID));
String staff_name=fname.concat(" "+lname);
owner_list.add(staff_name);
}
owner_list.add((String) getText(R.string.unassigned));
owner_id_list.add("0");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayAdapter<String> owner_Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,owner_list);
owner_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(owner_Adapter);
int owner_Position = owner_Adapter.getPosition(tv_owner.getText().toString());
spin.setSelection(owner_Position);
spin.performClick();
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// TODO Auto-generated method stub
String selected_owner = parent.getItemAtPosition(pos).toString();
String staff_id=owner_id_list.get(pos);
//*************************
Toast.makeText(getApplicationContext(),selected_owner+" "+staff_id , Toast.LENGTH_SHORT).show();
Log.d("selected owner : ",selected_owner);
Log.d("staff id is blank : ",staff_id);
if(staff_id!="")
{
String owner_filter="&vis_ticket_id="+Ticket_id+"&vis_action=staff&vis_update_id="+staff_id;
UPDATE_OWNER_URL=op.getUrl(getApplicationContext(),"ticket","update_properties",owner_filter);
JSONArray owner_array ;
}
//*************************
try
{
owner_array = new editProperties(UPDATE_OWNER_URL).execute().get();
String result=owner_array.toString();
if(result.equals("[\"success\"]"))
{
new ticketDetails().execute(); // parse other ticket details using AsyncTask
//tv_owner.setText(selected_owner);
}
else {Operation.showToast(getApplicationContext(), R.string.error);}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});

Try this, the overridden getCount method will reduce the number of spinner items by 1. But overriding this method only will hide only the last item in the spinner. So we will override the getDropDownView method to offset (push up) all items by 1. The end result will be only item 0 (the first item) is hidden.
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.your_spinner_layout, spinnerArray) {
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return super.getDropDownView(position + 1, convertView, parent);
}
public int getCount() {
return spinnerArray.size - 1;
}
};

Related

Spinner in Jasonette

I can`t find the Spinner in the Jsonette component list. Is there any replacement to allow the user to choose an item from the list? or should I develop the component as explained in the Jaonette documentation?
I could not find a spinner so have written my own (very primitive). Below is the code:
public class JasonSpinnerComponent {
public static View build(View view, final JSONObject component, final JSONObject parent, final Context context) {
if(view == null) {
return new Spinner(context);
} else {
try {
String data = component.getString("data");
final String[] spinnerData = data.split("\\|");
view = JasonComponent.build(view, component, parent, context);
JSONObject style = JasonHelper.style(component, context);
String type = component.getString("type");
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
(context, android.R.layout.simple_spinner_item,
spinnerData);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout
.simple_spinner_dropdown_item);
((Spinner)view).setAdapter(spinnerArrayAdapter);
((Spinner)view).setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
try {
((JasonViewActivity) context).model.var.put(component.getString("name"), spinnerData[position]);
} catch (JSONException e) {
Log.e("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
((Spinner)view).requestLayout();
return view;
} catch (Exception e){
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
return new View(context);
}
}
}
}
This works for a jasonette like this:
{
"type": "spinner",
"name": "gender",
"data": "Male|Female"
}
Let me repeat, this is very primitive and will undergo a lot of changes in future. But this can be a good starting point for someone looking for a spinner. I will be glad if it helped you.

Creating a very custom list

I'm developping an application, and now, I don't know what to do next:
I have a list of elements, each element has some informations + an ID + a logo.
What I want to do is creating a list like in the picture
List
Of course, I want it in a single layer, with the logo, some informations, and a button to define an action; where I could use the ID of the selected item.
I did some research, may be I found some relative subjects, but none of what I want.
My list is a
ArrayList<ArrayList<String>>
filled by data from database.
Thank you
Here it is:
public class Avancee extends Activity {
// Log tag
private static final String TAG = MainActivity2.class.getSimpleName();
// Movies json url
private static final String url = "http://blabla.com/movie.json";
private ProgressDialog pDialog;
private List<Movie> movieList = new ArrayList<Movie>();
private ListView listView;
private CustomListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
adapter = new CustomListAdapter(this, movieList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(this);
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// changing action bar color
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#1b1b1b")));
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
//Log.d(TAG, response.toString());
hidePDialog();
String result = getIntent().getStringExtra("ITEM_EXTRAA");
System.out.println(result);
try{
JSONArray ja = new JSONArray(result);
for (int i = 0; i < ja.length(); i++) {
try {
JSONObject obj = ja.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setLocation(obj.getString("location_search_text"));
movie.setId(obj.getInt("id"));
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
}
#Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
It's the "id" that I want to get in the OnClick event.
use this code
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Movie movie= movieList.get(position);
}
});
//here position will give you the id of listview cell so you can use it like
Movie movie= movieList.get(position);
then you can use it get all the data inside your moview object

Android Contextual Action Bar not appearing after item selection

In my android application, I am trying to show contextual action bar (CAB) in listview for item delete. The problem is that whenever an item is pressed for long, the item gets selected, but CAB doesn't appear. I have verified with so many tutorials, can't figure out what am I missing. Any help would be appreciated.
Adapter Class
public class DuasListAdapter extends ArrayAdapter<String>{
// class variables
private final Context context;// to save context
private final List<String> duas;// to save list of stores
LayoutInflater inflater;//
private SparseBooleanArray selectedItemsIds;
public DuasListAdapter(Context ctx,int resourceId, List<String> duasList) {
super(ctx, resourceId, duasList);
selectedItemsIds = new SparseBooleanArray();
context = ctx;// save context
duas = duasList;// save list of stores
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);// save inflater layout
}
*/
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_list_duas, null);
convertView.setTag(holder);
holder.duaIndex = position;
holder.background = (LinearLayout) convertView.findViewById(R.id.ll_duas_list);
holder.iv_duatype = (ImageView) convertView.findViewById(R.id.iv_duatype);
holder.tv_dua_arabic = (TextView) convertView.findViewById(R.id.tv_dua_arabic);
holder.tv_dua_no = (TextView) convertView.findViewById(R.id.dua_no);
}
else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
static class ViewHolder {
int duaIndex;
LinearLayout background;// background to display color for read and unread messages
ImageView iv_duatype;
TextView tv_dua_arabic;// title of message
TextView tv_dua_ref;// message by and message created on
TextView tv_dua_no;
/**
* #description constructor to save context and list of stores views
* #param v to refer the view
* #return
*/
}
public void remove(List<String> object){
duas.remove(object);
notifyDataSetChanged();
}
public List<String> getDuas(){
return duas;
}
public void toggleSelection(int position) {
selectView(position, !selectedItemsIds.get(position));
}
public void removeSelection() {
selectedItemsIds = new SparseBooleanArray();
notifyDataSetChanged();
}
public void selectView(int position, boolean value) {
if (value)
selectedItemsIds.put(position, value);
else
selectedItemsIds.delete(position);
notifyDataSetChanged();
}
public int getSelectedCount() {
return selectedItemsIds.size();
}
public SparseBooleanArray getSelectedIds() {
return selectedItemsIds;
}
}
Fragment Class
Context context;
LinearLayout ll_back_duas_list_header;
TextView ll_back_duas_list_header_title;
ListView lvDuaas;
public static DuasListAdapter duasAdapter;
ActionMode mAction;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = inflater.getContext();
View view = inflater.inflate(R.layout.fragment_list_duas, container, false);
ll_back_duas_list_header = (LinearLayout) view.findViewById(R.id.ll_back_duas_list_header);
ll_back_duas_list_header_title = (TextView) view.findViewById(R.id.ll_back_duas_list_header_title);
lvDuaas = (ListView) view.findViewById(R.id.lv_duas);
setHasOptionsMenu(true);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
String[] versesList = verses.split(",");
final ArrayList<String> duas = new ArrayList<String>();
for (int i = 0; i < versesList.length; i++) {
if (versesList[i].length() > 0)
duas.add(versesList[i]);
}
duasAdapter = new DuasListAdapter(context,R.layout.adapter_list_duas,duas);
lvDuaas.setAdapter(duasAdapter);
lvDuaas.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
lvDuaas.setChoiceMode(lvDuaas.CHOICE_MODE_MULTIPLE);
lvDuaas.setItemChecked(position, true);
mAction = getActivity().startActionMode(modeCallBack);
view.setSelected(true);
return true;
}
});
super.onActivityCreated(savedInstanceState);
}
ActionMode.Callback modeCallBack = new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(R.menu.activity_main, menu);
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode,
MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.delete:
// Calls getSelectedIds method from ListViewAdapter Class
SparseBooleanArray selected = duasAdapter
.getSelectedIds();
// Captures all selected ids with a loop
for (int i = (selected.size() - 1); i >= 0; i--) {
if (selected.valueAt(i)) {
String selecteditem = duasAdapter.getItem(selected.keyAt(i));
// Remove selected items following the ids
duasAdapter.remove(selecteditem);
}
}
// Close CAB
mode.finish();
return true;
default:
return false;
}
}
#Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
duasAdapter.removeSelection();
}
};
}
XML file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="#+id/delete"
android:title="#string/delete"
/>
</menu>
From looking at your code I can see the onCreateActionMode callback function returns false.
onCreateActionMode should return true if the action mode should be created, false if entering this mode should be aborted.
So when the user long clicks on the ListItem and the event is triggered it reaches onCreateActionMode and returns false. Telling it to abort. Hence no CAB menu appears. Try changing it to true and also adding in some logs to see if it ever makes it into the callback function.
This would be the change below:
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
Log.d("Test","In onCreateActionMode");
mode.getMenuInflater().inflate(R.menu.activity_main, menu);
return true;//code updated here
}
Android Link to reference : http://developer.android.com/reference/android/view/ActionMode.Callback.html#onCreateActionMode(android.view.ActionMode, android.view.Menu)

Using Camera and include an image of a layout

I have the next code, actually I have a main layer that shows the camera preview, and 2 layouts called R.layout.overlay and R.layout.controls, the layout of controls only show a button that take a picture, and the overlay have an image, what I try to do is that at the moment I take the picture the image that is in R.layout.overlay appear on the capture of the photo.
At the moment of preview before taking the photo it displays controls an image fine.
I don't know how to do this cause when I take the picture it takes it but without the image on R.layout.overlay.
Or is there a way to take an screenshot with some code? thats other option I have been thinking, but the problem of this is that the photo will be of the size of the resolution of the screen.
This is my code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
drawingView = new DrawingView(this);
LayoutParams layoutParamsDrawing
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(drawingView, layoutParamsDrawing);
controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control, null);
LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
inflater = LayoutInflater.from(getBaseContext());
View view = inflater.inflate(R.layout.overlay, null);
LayoutParams layoutParamsControl2= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(view, layoutParamsControl2);
buttonTakePicture = (Button)findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG);
}});
LinearLayout layoutBackground = (LinearLayout)findViewById(R.id.background);
layoutBackground.setOnClickListener(new LinearLayout.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
buttonTakePicture.setEnabled(false);
camera.autoFocus(myAutoFocusCallback);
}});
prompt = (TextView)findViewById(R.id.prompt);
}
//Termina onCreate
FaceDetectionListener faceDetectionListener
= new FaceDetectionListener(){
#Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (faces.length == 0){
prompt.setText(" No Face Detected! ");
drawingView.setHaveFace(false);
}else{
prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
drawingView.setHaveFace(true);
detectedFaces = faces;
}
drawingView.invalidate();
}};
AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){
#Override
public void onAutoFocus(boolean arg0, Camera arg1) {
// TODO Auto-generated method stub
buttonTakePicture.setEnabled(true);
}};
ShutterCallback myShutterCallback = new ShutterCallback(){
#Override
public void onShutter() {
// TODO Auto-generated method stub
}};
PictureCallback myPictureCallback_RAW = new PictureCallback(){
#Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
}};
PictureCallback myPictureCallback_JPG = new PictureCallback(){
#Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
/*Bitmap bitmapPicture
= BitmapFactory.decodeByteArray(arg0, 0, arg0.length); */
Uri uriTarget = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriTarget);
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
prompt.setText("Image saved: " + uriTarget.toString());
Toast.makeText(AndroidCamera.this, "Saved", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
camera.startPreview();
camera.startFaceDetection();
}};
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopFaceDetection();
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
prompt.setText(String.valueOf(
"Max Face: " + camera.getParameters().getMaxNumDetectedFaces()));
camera.startFaceDetection();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
camera.setFaceDetectionListener(faceDetectionListener);
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopFaceDetection();
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
private class DrawingView extends View{
boolean haveFace;
Paint drawingPaint;
public DrawingView(Context context) {
super(context);
haveFace = false;
drawingPaint = new Paint();
drawingPaint.setColor(Color.GREEN);
drawingPaint.setStyle(Paint.Style.STROKE);
drawingPaint.setStrokeWidth(2);
}
public void setHaveFace(boolean h){
haveFace = h;
}
#Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
if(haveFace){
// Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
// UI coordinates range from (0, 0) to (width, height).
int vWidth = getWidth();
int vHeight = getHeight();
for(int i=0; i<detectedFaces.length; i++){
int l = detectedFaces[i].rect.left;
int t = detectedFaces[i].rect.top;
int r = detectedFaces[i].rect.right;
int b = detectedFaces[i].rect.bottom;
int left = (l+1000) * vWidth/2000;
int top = (t+1000) * vHeight/2000;
int right = (r+1000) * vWidth/2000;
int bottom = (b+1000) * vHeight/2000;
canvas.drawRect(
left, top, right, bottom,
drawingPaint);
}
}else{
canvas.drawColor(Color.TRANSPARENT);
}
}
}
You can take a screenshot of your phone by physically pressing a combination of buttons. Thus, I guess there should be a way to do this programmatically, probably by overriding a callback somewhere. Check here: How to programmatically take a screenshot in Android?
But remember that when you are taking the screenshot, the image will have the same resolution of the phone display, and on old devices it may be very low. A picture taken with the camera will have a far better resolution. You can still add your image on the picture taken by simply merging the two images together.

How to work with LWUIT TABs click events

UPDATE:
My Requirement is to display two Rss files as Tabs on my LWUIT Form
Initially by default first Rss file titles and images should be displayed on first tab
if an end user click on second tab,we should be able to load the second rss file titles and images
I am able to load first Rss File titles,but i am not able to load the second tab if i click on it
How to capture the click event for LWUIT Tab?
Here my code which is not working:
String topNewsurl="TopNews.rss";
String topStoryurl="TopStory.rss";
public class XMLMidlet extends MIDlet{
public void startApp() {
Display.init(this);
Process p;
try {
p = new Process(this);
p.process();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public class Process extends Form {
Process(XMLMidlet midlet) throws IOException {
this.midlet=midlet;
topnews = new Vector();
topstory = new Vector();
tabs = new Tabs();
form1 = new Form();
form2=new Form();
form1.setLayout(new BorderLayout());
form1.setScrollable(false);
image = Image.createImage("/res/Tone.jpg");
Label icon = new Label(image);
form1.setTitleComponent(icon);
form2.setTitleComponent(icon);
form1.setTransitionInAnimator(Transition3D.createRotation(250, true));
try {
newsList = new List(topnews);
newsList.setScrollVisible(false);
newsList.setRenderer(new NewsListCellRenderer());
myNewsList = new List(topstory);
myNewsList.setScrollVisible(false);
myNewsList.setRenderer(new NewsListCellRenderer());
tabs.addTab("Topstory", newsList);
tabs.addTab("TopNews", myNewsList);
tabs.setChangeTabOnFocus(true);
form1.addComponent(BorderLayout.CENTER, tabs);
}
try{
String url = "http:topnews-20.rss";
form1.show();
ParseThread myThread = new ParseThread(this);
myThread.getXMLFeed(url);
} catch (Exception e) {
e.printStackTrace();
}
}
public void addNews(News newsItem) {
//log.debug("addnews");
//System.out.println("addNews");
topnews.addElement(newsItem);
newsList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
List source = (List) ae.getSource();
News selectedNewsItem = (News) source.getSelectedItem();
if (selectedNewsItem != null) {
displayCompleteNewsScreen(selectedNewsItem);
}
}
});
form1.show();
}
public void keyReleased(int keyCode) {
System.out.println("str");
Component p=this.getFocused();
String str= p.getClass().getName();
if(str.toLowerCase().indexOf("radiobutton")!=-1){
process();
}
From the very vague question it seems you want to capture key presses on a LWUIT Form.
jobsForm.addGameKeyListener(Display.GAME_FIRE,
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//do something here
}
});
jobsForm.addPointerPressedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
pointer_click = true;
}
});
jobsForm.addPointerReleasedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (pointer_click) {
//
}
pointer_click = false;
}
});
jobsForm.addPointerDraggedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//System.out.println("POINTER DRAGGED");
pointer_click = false;
}
});

Resources