×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    How to identify List item in lwuit Form Screen?

    i have developed Rss Reader App,and i have Successfully displayed on LWUIT Form Screen,which contains List of titles+images from Rss File .But,my Requirement is, when the user clicked on a title or an image,i have to navigate to one detailed form and there ,i should display the Rss (some data)related to the title user cicked,and after that,when the user clicks on back button on detailed form ,we need to go to the previous screen ?i confusing ,which method i have to use for this in LWUIT?any help?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: How to identify List item in lwuit Form Screen?

    Hi pavanragi,

    For this particular use case, it might be easier to use standard LCDUI Components, instead of LWUIT on full touch Series 40 devices. One suggestion would be to use the following code:
    Code:
    import java.io.IOException;
    
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.List;
    import javax.microedition.lcdui.Spacer;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    public class ListImplicitMIDlet 
    	extends MIDlet
    	implements CommandListener {
    
    	List list;
    	Command exitCmd = new Command("Exit", Command.EXIT,0);
    	Command okCmd = new Command("OK", Command.OK, 0);
    	Command backCmd = new Command("Exit", Command.EXIT, 0);
    	
    	Form result;
    	Image image;
    	
    	protected void destroyApp(boolean unconditional)
    			throws MIDletStateChangeException {
    		// TODO Auto-generated method stub
    	}
    
    	protected void pauseApp() {
    		// TODO Auto-generated method stub
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		result = new Form("Result");
    		result.append("You have been redirected");
    		result.setCommandListener(this);
    		result.addCommand(backCmd);
    		
    		list = new List("Notifications", List.IMPLICIT);
    		try {
    			image = Image.createImage("/icons.png");
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		Spacer spacer = new Spacer(300, 500);
    		for(int i = 0; i < 2; i++){
    			list.append("choice item " + (i + 1), image);
    		}
    		list.addCommand(exitCmd);
    		list.addCommand(okCmd);
    		list.setCommandListener(this);
    		Display.getDisplay(this).setCurrent(list);
    	}
    
    	public void commandAction(Command c, Displayable d) {
    		if(c == okCmd) {
    			System.out.println("Some task for Action Button 1");
    		}
    		else if(c == exitCmd) {
    			notifyDestroyed();
    		}
    		else if(c == backCmd) {
    			Display.getDisplay(this).setCurrent(list);
    		}
    		else {
    			Display.getDisplay(this).setCurrent(result);
    		}
    	}
    }
    Keep in mind that you can always combine LWUIT and LCDUI in the same MIDlet, so I would suggest that you switch from this LCDUI list to an LWUIT Form according to your needs.
    Last edited by skalogir; 2012-08-07 at 11:15.

  3. #3
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: How to identify List item in lwuit Form Screen?

    Hi pavanragi,

    use following code
    list.addActionListener(this);
    public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    if (src == list){
    Object selected = list.getSelectedItem();
    //navigate to another view where you can display detailed information about each link
    }
    }

  4. #4
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    Re: How to identify List item in lwuit Form Screen?

    Hi bandarap,
    Thanks for reply,i have used the below code,i am able to display the detailed form information,but it is giving the java.lang.ClassCastException after clicking the list items for 4th or 5th time?

    Here my Code:

    public void actionPerformed(ActionEvent ae) {
    List source = (List)ae.getSource();
    int selectedIndex = source.getSelectedIndex();
    if(selectedIndex != -1){
    newsItem1 = (News)newsVector.elementAt(selectedIndex);
    Label l=new Label();
    l.setText(newsItem1.getPubDate());
    Form detailedForm=new Form();
    detailedForm.addCommand(m_backCommand);
    detailedForm.addCommandListener(this);
    detailedForm.addComponent(l);
    detailedForm.show();

    }
    Last edited by pavanragi; 2012-08-07 at 19:42.

  5. #5
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: How to identify List item in lwuit Form Screen?

    Use list.getSelectedItem(); to get the selected item and set that item to label. It should do the same as newsVector item.
    Do the following changes:
    public void actionPerformed(ActionEvent ae) {
    List source = (List)ae.getSource();
    Object selectedItem = source.getSelectedItem();// try block code
    if(selectedItem != null){
    Label l=new Label();
    l.setText(selectedItem);//try next block code
    Form detailedForm=new Form();
    detailedForm.addCommand(m_backCommand);
    detailedForm.addCommandListener(this);
    detailedForm.addComponent(l);
    detailedForm.show();
    }
    if list items has more than text(images etc), cast to list item object and then get the text details like below
    NewsItem selectedNewsItem = (NewsItem) source.getSelectedItem();
    l.setText(selectedNewsItem.getNewsItemText());
    if you could share what kind of news item are added to News vector, it’s easy to say.
    Also paste whole exception call stack here.

  6. #6
    Registered User
    Join Date
    Jul 2012
    Location
    India
    Posts
    103

    Re: How to identify List item in lwuit Form Screen?

    Thanks bandarap,
    i have changed my code,it is working fine.......,but ,in my detailed form i need to display Paragraph of text and publish date ,i having those details in my NewsItem class.if i use label component to display the description ,i am able to display only one line of text with dot's........how can i display full description and publish date,with headings....?

    Quote Originally Posted by bandarap View Post
    Use list.getSelectedItem(); to get the selected item and set that item to label. It should do the same as newsVector item.
    Do the following changes:

    if list items has more than text(images etc), cast to list item object and then get the text details like below

    if you could share what kind of news item are added to News vector, it’s easy to say.
    Also paste whole exception call stack here.
    Last edited by pavanragi; 2012-08-08 at 06:26.

  7. #7
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: How to identify List item in lwuit Form Screen?

    use
    Label -> heading
    TextArea/TextField -> paragraph
    Label -> date display

    feel free to choose components from LWUIT Java docs

Similar Threads

  1. How to append LWUIT List screen to a LWUIT Form in j2me?
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-06, 07:01
  2. blank vector item appended to a LWUIT list
    By ali30 in forum Mobile Java General
    Replies: 1
    Last Post: 2012-03-19, 20:33
  3. how to show a new form while selecting a list item...
    By josephcarmel in forum Mobile Java General
    Replies: 2
    Last Post: 2009-03-07, 08:12
  4. Depend on the selected List Box item , redirect to another Form ?
    By waruni.k in forum Symbian User Interface
    Replies: 6
    Last Post: 2008-09-02, 03:43
  5. How to include setting item list in a form
    By anand_zain76 in forum Symbian User Interface
    Replies: 11
    Last Post: 2006-06-01, 13:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •