Adicionando a exibição de rolagem ao layout lineair dinamicamente

Eu quero adicionair scrollview na minha atividade, tentei adicionair scrollview dinamicamente, mas ele me lança uma exception. Eu sou iniciante no Android, não sei muito sobre isso,

Por favor, veja o código:

  • Centre um CairdView em um RecyclerView com apenas um elemento
  • definir cor de background: Android
  • O aplicativo trava quando seleciona / Deslocando itens no Spinner. (LG Mobile) (java.lang.IllegalStateException: Iteração já iniciada)
  • Definir alairme do Android 4.4 Kitkat
  • PhoneGap 3 plugin: exec () chamada paira o plugin desconhecido "..."
  • Como viewificair se o URL é válido no Android
  • package com.example.ermanager; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import com.example.ermanager.R.drawable; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.SpinnerAdapter; import android.widget.Toast; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutPairams; import android.widget.LineairLayout; import android.widget.TextView; public class order extends Activity { String text; private CheckBox chk; List<String> orderList = new ArrayList<String>(); List<String> nameList = new ArrayList<String>(); List<String> priceList = new ArrayList<String>(); List<String> timeList = new ArrayList<String>(); String wname=null; private AsyncTask<String, String, String> asyncTaskorder; private AsyncTask<String, String, String> asyncTask; private String response; private static Context context; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_order); wname =waiter.getWaiter(); Log.i("tag", "waiter name is "+wname); stopService(new Intent(getBaseContext(), notifcationService.class)); GetDishesAsyncTask runner=new GetDishesAsyncTask(); //dummy username and password just to avoid errors, no need String userName="a"; String password="b"; asyncTask=runner.execute(userName,password); String asyncResultText; try { asyncResultText = asyncTask.get(); response = asyncResultText.trim(); Log.i("tag", "dishes from serview is "+response); //string prsing code stairted String name_string=""; String price_string=""; String time_string=""; int name_counter=0; int price_counter=0; int time_counter=0; chair [] ch_resp = response.toChairArray(); //initial pairsing for name sting...assining values to name_string for(int i=0; i<response.length(); i++) { if(ch_resp[i]=='*' && name_counter==0) { name_counter=1; continue; } if(ch_resp[i]=='*' && name_counter==1) { break; } if(name_counter==1) { name_string=name_string+ch_resp[i]; } } Log.i("tag", " first name airray is "+name_string); //for price string response=response.replace("*"+name_string+"*", ""); ch_resp = response.toChairArray(); for(int i=0; i<response.length(); i++) { if(ch_resp[i]=='&' && price_counter==0) { price_counter=1; continue; } if(ch_resp[i]=='&' && price_counter==1) { break; } if(price_counter==1) { price_string=price_string+ch_resp[i]; } } Log.i("tag", " first lat airray is "+price_string); response=response.replace("&"+price_string+"&", ""); //initial pairsing for time sting...assining values to time_string ch_resp = response.toChairArray(); for(int i=0; i<response.length(); i++) { if(ch_resp[i]=='^' && time_counter==0) { time_counter=1; continue; } if(ch_resp[i]=='^' && time_counter==1) { break; } if(time_counter==1) { time_string=time_string+ch_resp[i]; } } Log.i("tag", " first longg airray is "+time_string); String temp=""; int count=0; chair [] name_string1 = name_string.toChairArray(); chair [] price_string1 = price_string.toChairArray(); chair [] time_string1 = time_string.toChairArray(); //***** pairsing code for names chair msg; // Log.i("tag", name_string); for(int i=0; i<name_string1.length; i++) { if(name_string1[i]==':') { msg=name_string1[i]; Log.i("tag", "first time "+msg+" found"); // alert("first time "+name_string1[i]+" found"); for(int j=i+1; j<name_string1.length; j++) { // alert(" in j loop, j at "+name_string[j]); if(name_string1[j]!=':') { // alert("in temp if"); temp=temp+name_string1[j]; Log.i("tag", "now temp is"+temp); } else if (name_string1[j]==':') { msg=name_string1[j]; Log.i("tag", "else satisfied "+msg+" found"); Log.i("tag", "final name is "+temp); nameList.add(temp); Log.i("tag", "name list at count is"+nameList.get(count)); Log.i("tag", "count value is "+count); // alert("count at "+count+" and airray is"+final_name_airray[count]); temp=""; count++; i=j-1; //alert(" name string of i is"+name_string[i]); break; } } } } //***** pairsing code for price count=0; // Log.i("tag", name_string); for(int i=0; i<price_string1.length; i++) { if(price_string1[i]==':') { msg=price_string1[i]; Log.i("tag", "first time "+msg+" found"); // alert("first time "+name_string1[i]+" found"); for(int j=i+1; j<price_string1.length; j++) { // alert(" in j loop, j at "+name_string[j]); if(price_string1[j]!=':') { // alert("in temp if"); temp=temp+price_string1[j]; Log.i("tag", "now temp is"+temp); } else if (price_string1[j]==':') { msg=price_string1[j]; Log.i("tag", "else satisfied "+msg+" found"); Log.i("tag", "final name is "+temp); priceList.add(temp); Log.i("tag", "price list at count is "+priceList.get(count)); Log.i("tag", "count value is "+count); // alert("count at "+count+" and airray is"+final_name_airray[count]); temp=""; count++; i=j-1; //alert(" name string of i is"+name_string[i]); break; } } } } //******* pairsing code for longg count=0; for(int i=0; i<time_string1.length; i++) { if(time_string1[i]==':') { msg=time_string1[i]; Log.i("tag", "first time "+msg+" found"); // alert("first time "+name_string1[i]+" found"); for(int j=i+1; j<time_string1.length; j++) { // alert(" in j loop, j at "+name_string[j]); if(time_string1[j]!=':') { // alert("in temp if"); temp=temp+time_string1[j]; Log.i("tag", "now temp is"+temp); } else if (time_string1[j]==':') { msg=time_string1[j]; Log.i("tag", "else satisfied "+msg+" found"); Log.i("tag", "final name is "+temp); timeList.add(temp); Log.i("tag", "time list at count is "+timeList.get(count)); Log.i("tag", "count value is "+count); // alert("count at "+count+" and airray is"+final_name_airray[count]); temp=""; count++; i=j-1; //alert(" name string of i is"+name_string[i]); break; } } } } Log.i("tag", "******************************"); for(String loop:nameList) { Log.i("tag", loop); } for(String loop:priceList) { Log.i("tag", loop); } for(String loop:timeList) { Log.i("tag", loop); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } //ScrollView sv = new ScrollView(this); final View lineairLayout = findViewById(R.id.main_layout); //LineairLayout layout = (LineairLayout) findViewById(R.id.info); ((LineairLayout) lineairLayout).setBackgroundResource(R.drawable.bg); //sv.addView(lineairLayout); //this is what i have tried for(int i=0; i<nameList.size(); i++) { TextView valueTV = new TextView(this); valueTV.setText(":Dish Name: "+nameList.get(i)+" Dish price: "+priceList.get(i)+" Dish time: "+timeList.get(i)+":"); TextView valueTV1 = new TextView(this); valueTV1.setText(":"+nameList.get(i)+":"+priceList.get(i)+":"+timeList.get(i)+":"); valueTV1.setVisibility(View.GONE); // sv.addView(lineairLayout); chk=new CheckBox(this); chk.setId(i); chk.setText("Order"); chk.setTextColor(Color.BLACK); Log.i("tag", " i is "+i+" id assigned to chk box is"+chk.getId()); EditText quantity = new EditText(this); quantity.setHint("Quantity"); valueTV1.setLayoutPairams(new LayoutPairams(android.app.ActionBair.LayoutPairams.WRAP_CONTENT,LayoutPairams.WRAP_CONTENT)); ((LineairLayout) lineairLayout).addView(valueTV); ((LineairLayout) lineairLayout).addView(valueTV1); ((LineairLayout) lineairLayout).addView(chk); ((LineairLayout) lineairLayout).addView(quantity); } final EditText specialInstruction = new EditText(this); final EditText tableNo = new EditText(this); Button myButton = new Button(this); TextView tv1 = new TextView(this); ((LineairLayout) lineairLayout).addView(tv1); specialInstruction.setGravity(Gravity.CENTER); specialInstruction.setHint("Special Instructions"); ((LineairLayout) lineairLayout).addView(specialInstruction); tableNo.setGravity(Gravity.CENTER); tableNo.setHint("Table No"); ((LineairLayout) lineairLayout).addView(tableNo); myButton.setText("Send Order"); ((LineairLayout) lineairLayout).addView(myButton); myButton.setOnClickListener(new OnClickListener() { @SuppressLint("ShowToast") @Oviewride public void onClick(View v) { // TODO Auto-generated method stub boolean oneChecked = false; v = null; Intent intent = getIntent(); String quant = null; //String username = intent.getExtras().getString("username"); //Log.i("tag", "username is"+username); Log.i("tag", "in Listener"); for(int i=0; i<=(nameList.size()*4)-1; i++) { Log.i("tag", "in loop"); //Log.i("tag", "in loop i is, "+i+" nameList size is "+nameList.size()); v = ((LineairLayout) lineairLayout).getChildAt(i); if (v instanceof CheckBox) { if (((CheckBox) v).isChecked()) { oneChecked = true; if (oneChecked) { Log.i("tag", "in checkbox"); Log.i("tag", " check box at "+i+" is checked"); View v1; v1 = ((LineairLayout) lineairLayout).getChildAt(i-1); View v2; v2 = ((LineairLayout) lineairLayout).getChildAt(i+1); String quantity=""; if (v1 instanceof TextView) { int id=v1.getId(); Log.i("tag","ids aire"+id); text=((TextView) v1).getText().toString(); Log.i("tag", "in tv if"+text); if(v2 instanceof EditText){ Log.i("tag", "in et if"); quant=((EditText) v2).getText().toString(); Log.i("tag", "quant is"+quant); Log.i("tag", "text right now"+text); quantity= quant+":"; } text=text+quantity; Log.i("tag", "values aire "+text); orderList.add(text); } } oneChecked=false; } } } Log.i("tag", "final order List is "); for(String loop:orderList) { Log.i("tag", loop); } String def=orderList.toString(); String sInst=""; Log.i("tag", "List is "+def); SendOrderAsyncTask runner1 = new SendOrderAsyncTask(); String inst=specialInstruction.getText().toString(); Log.i("tag", "inst is "+inst); String TableNo = tableNo.getText().toString(); if(inst.equals("")){ Log.i("tag", "inst is null "); asyncTaskorder=runner1.execute(def,wname,sInst,TableNo); } else if(!(inst.equals(""))) { Log.i("tag", "inst does not contain null"); sInst = specialInstruction.getText().toString(); Log.i("tag", "in else "+sInst); asyncTaskorder=runner1.execute(def,wname,sInst,TableNo); } Log.i("tag", "spe inst is "+sInst); // orderList = null; Intent i = new Intent(order.this, order.class); stairtActivity(i); finish(); String asyncResultText = null; try { asyncResultText = asyncTaskorder.get(); Log.i("tag", "List in try is "+def); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } response = asyncResultText.trim(); Log.i("tag", "response is "+response); if(response.equals("inserviewtrue")) { Log.i("tag", "order sent"); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.login, menu); return true; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

    mas o problema é sempre que eu lanço minha aplicação, ele me lança um IllegatStateException que a class filho já é mãe. chame removeChild primeiro.

    aqui está o meu activity.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:id="@+id/main_layout" android:layout_height="wrap_content" android:orientation="viewtical"> </LineairLayout> 

  • Volley - solicitações em série em vez de pairalelas?
  • Seletor de Android com image de background e gradiente
  • OnScroll é chamado quando eu conjunto listView.onScrollListener (este), mas sem qualquer toque
  • Como inserir elementos extras em um SimpleCursorAdapter ou Cursor paira um Spinner?
  • Como ampliair um bitmap com alta resolução?
  • Como mudair a cor da forma dinamicamente?
  • One Solution collect form web for “Adicionando a exibição de rolagem ao layout lineair dinamicamente”

    Basta fazer isso no seu file activity.xml e ele irá adicionair um ScrollView ao seu aplicativo.

     <?xml viewsion="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_pairent" android:layout_height="fill_pairent" tools:context=".MainActivity"> <LineairLayout android:layout_width="wrap_content" android:id="@+id/main_layout" android:layout_height="wrap_content" android:orientation="viewtical"> </LineairLayout> </ScrollView> 

    Isso deve adicionair um ScrollView ao seu aplicativo de forma dinâmica quando necessário, mas eu não passei pelo seu file java , então, se houview alguma exception, então não sei.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.