Android: Accessing web-service/parsing xml file

This simple project is created to retrieve data using web-service and then parsing the xml. Using relativelayout all parsed data was displayed dynamically.

RelativeLayout that was used to display fetched data was needed to integrate with other static layout. But that was handled carefully.Here is the  mechanism how i controlled dynamic view.

ViewId variable should be declared as a global Variable.

public int viewId;

The following piece of code should be declared within onCreate Method. Here ckBox is the ChekcBox View below which all dynamic views will be created.

viewId = ckBox.getId();

This is the dynamic view method which is called with the fetch of new data.


public void DynamicView(String val) {
 // param for view
 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

// Log.d("","View ID: "+viewId);
 params.addRule(RelativeLayout.BELOW, viewId);
 // create a layout
 RelativeLayout layout = (RelativeLayout) findViewById(R.id.relLayout);

TextView tv = new TextView(this);

 tv.setId(thresholdViewId);
 tv.setText(val);
 tv.setLayoutParams(params);
 viewId = thresholdViewId;
 thresholdViewId++;

 layout.addView(tv);

 }

Code can be found in this location.: https://www.box.net/shared/zljfqtmi8j9kzkibci58

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s