Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi . im developing an android application . this application should give data from web and show it .
the problem is , it gives data very well . but it cant show it !
surprisingly i debugged my application but i couldn't find any problem or Exception ! if you let me i show you my code Complitly and after that i explain it part by part .

Code :

Java
public class MainActivity extends Activity {	
	
	String WebData="";// Data from Web Server	
	int DC=0;// Data Counter 	
	String []SplitData=new String[10] ;	//Split Data array
	
	
	protected void DataCollector(String ReciveData)
	{		
	WebData=ReciveData;	
	}
    private void Spliter()
    {  	
    SplitData=WebData.split("-");   
    }
	private void CreateUI()
	{
		String BtnText="";
		Button B=null;		
		LinearLayout ll=(LinearLayout)findViewById(R.id.ll);
		try
		{
		for(String aSplitData : SplitData)
			{			
			BtnText=aSplitData.split("/")[0];
			B=new Button(this);			     B.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);			
			B.setText(BtnText);
			ll.addView(B);			
			}
		}
		catch(Exception ex)
		{
			Log.d("Error : ",ex.toString());
		}
	}	
	
	class RetrieveFeedTask extends AsyncTask {
	   
		protected String doInBackground(String...Urls) {
	    	try
	    	{
	    			    		
	    		HttpURLConnection urlConnection = null;	    		  		
	    	    URL myUrl=new URL("http://10.0.2.2:80/mob1/Default.aspx");	    
	    		urlConnection = (HttpURLConnection)myUrl.openConnection();		
	    		BufferedReader in = new BufferedReader (new InputStreamReader(urlConnection.getInputStream()));    		
	    		String temp="";	     
	    		while((temp=in.readLine())!=null)
	    		{    			
	    			DataCollector(temp);    		
	    		}	    		
	    	    if(urlConnection!=null){
	    	    urlConnection.disconnect(); 	
	    	    } 	    		    			
	    	}	    	
	    		catch(Exception e)
	    		{
	    		Log.d("error",e.toString());
	    		return "1";
	    	
	    		}
	    	return "1";	
	    }		
		protected void onPostExecute(String Result)
	    {
	    	//	      
	    }
	

	}	
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
    	        setContentView(R.layout.activity_main);	
		new RetrieveFeedTask().execute();	
		Spliter();
		CreateUI();
		
		
    	
	}

}


as i said it Gives Data, but when it wants to Create buttons ( CreateUI() ) it makes only one button without any text! if you debug my Cod you cant find any Exception it seems everything Works well !

Java
private void CreateUI()
	{
		String BtnText="";
		Button B=null;		
		LinearLayout ll=(LinearLayout)findViewById(R.id.ll);
		try
		{
		for(String aSplitData : SplitData)
			{			
			BtnText=aSplitData.split("/")[0];
			B=new Button(this);			  B.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);			
			B.setText(BtnText);
			ll.addView(B);			
			}
		}
		catch(Exception ex)
		{
			Log.d("Error : ",ex.toString());
		}
	}


also i changed my code and Set Buttons Text Directly . it worked ! it made 10 buttons !

Java
LinearLayout ll=(LinearLayout)findViewById(R.id.ll);
for(int i=0;i<=9;i++)
 {
B=new Button(this);			B.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);			
			B.setText("1");
			ll.addView(B);
 }


what do you think or suggest ?
Posted
Updated 21-Dec-14 6:52am
v2
Comments
ridoy 22-Dec-14 3:25am    
your 10 buttons positioned one over another, change the position of them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900