Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
giblartar2
Posts: 10
Registered: ‎06-10-2013
My Device: 8520
My Carrier: indosat
Accepted Solution

how to get selected item listfield and goto next page?.

Assalaamualikum :smileyhappy:

 

i trying to parsing xml data from url and show in listfield.

 

problem :

how to get selected item and  passing variable  and than goto next page ?.

 

 

 

my code  :

 

package parsepack;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class xmlparsing extends UiApplication implements ListFieldCallback, FieldChangeListener
{

public static void main(String[] args)
{
xmlparsing app = new xmlparsing();
app.enterEventDispatcher();
}


public long mycolor ;
Connection _connectionthread;
private static ListField _list;
private static Vector listElements = new Vector();
public MainScreen screen = new MainScreen();
VerticalFieldManager mainManager;
VerticalFieldManager subManager;

 

public xmlparsing()
{
super();
pushScreen(screen);

final Bitmap backgroundBitmap = Bitmap.getBitmapResource("blackbackground.png");

mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
{

public void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, Display.getWidth(),Display.getHeight(),backgroundBitmap, 0, 0);

super.paint(graphics);
}

};

subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();

super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};


screen.add(mainManager);

_list = new ListField()

{

public void paint(Graphics graphics)

{
graphics.setColor((int) mycolor);
super.paint(graphics);

}

};
mycolor = 0x00FFFFFF;
_list.invalidate();
_list.setEmptyString("* Feeds Not Available *", DrawStyle.HCENTER);
_list.setRowHeight(50);
_list.setCallback(this);
mainManager.add(subManager);
listElements.removeAllElements();
_connectionthread = new Connection();
_connectionthread.start();
}


protected boolean navigationClick(int status, int time)
{
try
{
//navigate here to another screen if you need.


}
catch(Exception e)
{
System.out.println("Exception:- : navigationClick() "+e.toString());
}
return true;
}

 

private class Connection extends Thread
{
public Connection()
{
super();
}

public void run() {
Document doc;
StreamConnection conn = null;
InputStream is = null;
try {

conn = (StreamConnection) Connector.open("http://ec2-54-248-241-248.ap-northeast-1.compute.amazonaws.com/koperasi-akr-trial/cgi-bin/gw-pinjama...

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
docBuilderFactory.setCoalescing(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.isValidating();
is = conn.openInputStream();
doc = docBuilder.parse(is);
doc.getDocumentElement().normalize();
NodeList list = doc.getElementsByTagName("ID");
for (int i = 0; i < list.getLength(); i++) {
Node textNode = list.item(i).getFirstChild();
listElements.addElement(textNode.getNodeValue());
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (is != null) {
try { is.close();
} catch (IOException ignored) {}
} if (conn != null) {
try { conn.close(); }
catch (IOException ignored) {}
} } UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
_list.setSize(listElements.size());
subManager.add(_list);
screen.invalidate();
}
});
}

}


public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String tes = (String)listElements.elementAt(index);
int yPos = 0+y;
g.drawLine(0, yPos, w, yPos);
g.drawText(tes, 5, 15+y, 0, w);
}


public Object get(ListField list, int index)
{
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String prefix, int string)
{
return listElements.indexOf(prefix, string);
}
public int getPreferredWidth(ListField list)
{
return Display.getWidth();
}
public void insert(String toInsert, int index) {
listElements.addElement(toInsert);
}

public void fieldChanged(Field field, int context) {


}
}

 

thanks.

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: how to get selected item listfield and goto next page?.

you can override navigationClick method in the listfiled and in the navigationClick() method you can get the index of selected item by using
int index = list.getSelectedIndex();// here list is object of listfiled  

and pass that index value to listElements vector in your code to get the item

Please use plain text.
Contributor
giblartar2
Posts: 10
Registered: ‎06-10-2013
My Device: 8520
My Carrier: indosat

Re: how to get selected item listfield and goto next page?.

can you give me sample code Mr.!! how to pass that index value ?

 

i want to passing value of  "ID" to another page.


Achin wrote:

you can override navigationClick method in the listfiled and in the navigationClick() method you can get the index of selected item by using
int index = list.getSelectedIndex();// here list is object of listfiled  

and pass that index value to listElements vector in your code to get the item


 

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: how to get selected item listfield and goto next page?.

you import that sample.., but  passing value of  "ID" to another page. you have to search yourself

Please use plain text.
Developer
rishikeshsinghpbh
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: how to get selected item listfield and goto next page?.

[ Edited ]

To pass the value of ID to other page, you can do it like following;

suppose you want to pass the ID to RecieverScreen then

 

class RecieverScreen extends MainScreen{

int id;

public RecieverScreen(int id){

this.id = id

}

}

 

and while pushing screen on List click use the following--

 

UiApplication.getUiApplication().pushScreen(new RecieverScreen(id));

 

Rishikesh Singh
Please use plain text.
Contributor
giblartar2
Posts: 10
Registered: ‎06-10-2013
My Device: 8520
My Carrier: indosat

Re: how to get selected item listfield and goto next page?.

hy..

what wrong with my code, ?

protected boolean navigationClick(int status, int time)
{
int index = _list.getSelectedIndex();
String text = (String)listElements.elementAt(index);
Dialog.inform(""+text);
return true;
}

when i click listfield item no action work, just showing menu.


Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: how to get selected item listfield and goto next page?.

i have told you that override the navigationclick() method where you intialize your listfield

like i think chnage your code and then reply me

_list = new ListField()
{
protected boolean navigationClick(int status, int time)
{
  Dialog.inform("hi");
  return true;
}

public void paint(Graphics graphics)
{
graphics.setColor((int) mycolor);
super.paint(graphics);
}
};

 

Please use plain text.
Contributor
giblartar2
Posts: 10
Registered: ‎06-10-2013
My Device: 8520
My Carrier: indosat

Re: how to get selected item listfield and goto next page?.

[ Edited ]

yes, it's work!! thanks.

 

May I ask again?.

 

i have Main.class, its used for Menu navigation.

 when btnPinjaman is clicked i want go to xmlparsing.class above 

 

I have done the following :

 

package com.ksp;

import com.ksp.Formloginscreen.Global;

import net.rim.device.api.system.Application;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class Main extends MainScreen{
	
	
	public Main()
	{
	
		
		LabelField login =  new LabelField("Aplikasi Koperasi Online", LabelField.FIELD_HCENTER);
		login.setFont(Font.getDefault().derive(Font.BOLD, 30));
		login.setMargin(10,0,20,0);
		
		HorizontalFieldManager btns = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
		
		
		ButtonField pinjBtn = new ButtonField("Pinjaman", ButtonField.CONSUME_CLICK);
		
		
		btns.add(pinjBtn);
		add(login);
		add(btns);
		
		pinjBtn.setChangeListener(btnPinjaman);
	}
	
		
		
	FieldChangeListener btnPinjaman = new FieldChangeListener() {
		
		public void fieldChanged(Field field, int context) {
			UiApplication.getApplication().pushScreen(new xmlparsing());
			
			
		}
	};

		
		
}

what wrong with my code?

 


Achin wrote:

i have told you that override the navigationclick() method where you intialize your listfield

like i think chnage your code and then reply me

_list = new ListField()
{
protected boolean navigationClick(int status, int time)
{
  Dialog.inform("hi");
  return true;
}

public void paint(Graphics graphics)
{
graphics.setColor((int) mycolor);
super.paint(graphics);
}
};

 




Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: how to get selected item listfield and goto next page?.

yes you can ask again but first plz click on the
Accept as Solution button.
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: how to get selected item listfield and goto next page?.

and what error you got when you press the button to go to next screen..
Please use plain text.