Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello . i am trying to make an android's UI programmatically.
Part 1 :
indeed at the first step i get the data from web server and save it in array . the first step works very well and it doesn't have any problem .
here this is the code of first step :
Java
protected String doInBackground(String...Urls){
			String Data="";
			HttpURLConnection urlConnection = null;	
			try{
	    	    URL myUrl=new URL("http://10.0.2.2:80/Urgence/Default.aspx?type="+Type);
	    	    urlConnection = (HttpURLConnection)myUrl.openConnection();		
	    		BufferedReader in = new BufferedReader (new InputStreamReader(urlConnection.getInputStream()));    		
	    		String temp="";	
	    		// Data is used to store Server's Response 
	    		while((temp=in.readLine())!=null)
	    		{    			
	    			 Data=Data+temp;   		
	    		}    
			}
			catch(Exception ex){
				Log.d("Er>doInBackground", ex.toString());
				urlConnection.disconnect();	
			}
			finally{
				urlConnection.disconnect();
				}
				return Data;// it sends Result to onPostExcute 			
		}
		protected void onPostExecute(String Data){
			try{
			serverResponsesArray=Data.split("/",3);
			makeItems(serverResponsesArray);
			dialog.cancel();			
			}
			catch(Exception ex){
				Log.d("Er>onPostExecute",ex.toString());
			}
			finally{
			 dialog.cancel();
			}
	    }


part 2 :

in second step i want to make an UI and show my data in some Rows !
if you notice to my code you can realize that i use a TextView to show array's members(subject,writer,main text,Date) . at first i use TextView for showing (Date,writer and subject) and after that i use it to show the main text . now it shows Date , Time and writer but it doesn't show the main text ! amazingly it increases the row's height but i cant see any main text ! i have debugged my code 3 times but it didnt have any problem !! now do me a favor and tell me what is the exact problem in my code ?! thanks in advance
code of second part :

Java
public void makeItems(String Data[]){
		int marginHorizontal=(int)getResources().getDimension(R.dimen.lpll_marginhor);// it is used to set llc's margin
		int marginVertical=(int)getResources().getDimension(R.dimen.lpll_marginver);// it is used to set margin
		int txtMargin=(int)getResources().getDimension(R.dimen.lptvmargin);// it is used to set TextView's margin
		Typeface face=Typeface.createFromAsset(getAssets(),"Font/ADOBEARABIC-REGULAR.OTF");
		LayoutParams lpll;//		
		LinearLayout llm=(LinearLayout)findViewById(R.id.contentMainLLayout);//main linear Layout
		LinearLayout llc;// Linear Layout as a Item's Row
		TextView tv;
		LayoutParams lptv;// it is used to set TextView's LayoutParams		
		String separateDataArray[]=new String[4];
		try{
		for(int i=0;i<=2;i++){
			separateDataArray=Data[i].split("-",4);//
			llc=new LinearLayout(this);
			llc.setOrientation(LinearLayout.HORIZONTAL);
			lpll= new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
			lpll.setMargins(marginVertical,marginHorizontal,marginVertical,marginHorizontal);
			llc.setLayoutParams(lpll);
			if(i%2==0){
			llc.setBackgroundColor(getResources().getColor(R.color.bcfbc8));	
			}
			else{
				llc.setBackgroundColor(getResources().getColor(R.color.bcd1fb));	
			}
			lptv=new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);//
			lptv.setMargins(txtMargin,txtMargin,txtMargin,txtMargin);//
			// tv shows date , writer and subject
			tv=new TextView(this);//			
			tv.setTypeface(face);//
			tv.setTextSize(getResources().getDimension(R.dimen.content_item_txtsize));//*						
			tv.setText(" موضوع : "+separateDataArray[0]+"\n"+" نویسنده : "+separateDataArray[2]+"\n"+" تاریخ : "+separateDataArray[1]);//			
			tv.setLayoutParams(lptv);			
			llc.addView(tv);
			// new tv shows main text 
			tv=new TextView(this);
			tv.setTypeface(face);//
			tv.setTextSize(getResources().getDimension(R.dimen.content_item_txtsize));//*	
			tv.setGravity(Gravity.CENTER);
			tv.setText(separateDataArray[3]);			
			tv.setLayoutParams(lptv);	
			llc.addView(tv);			 
			//
			llm.addView(llc);
			}
		}
		catch(Exception ex){
			Log.d("Er>makeItems",ex.toString());
		}
	}
Posted
Updated 29-Mar-15 5:49am
v2

1 solution

i think i solved it ! just change this line :
llc.setOrientation(LinearLayout.VERTICAL);

but i dont know the reason !
 
Share this answer
 

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