2012-03-20 4 views
44

के अंदर सभी वस्तुओं को हटाएं मैं एक लाइनरलेआउट बनाता हूं जो एक XML आइटम से संबंधित है। इस लाइनरलेआउट के अंदर मैंने कुछ टेक्स्टव्यू गतिशील रूप से रखा है, इसलिए उन्हें एक्सएमएल से ले जाये बिना। अब मुझे लाइनरलेआउट से इन टेक्स्टव्यू को हटाने की जरूरत है। मैंने यह कोशिश की:लाइनरलेआउट

if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0) 
    ((LinearLayout) linearLayout.getParent()).removeAllViews(); 

लेकिन यह काम नहीं करता है। मैं कैसे कर सकता हूं? धन्यवाद, मेटिया

उत्तर

115

तुम क्यों linearLayout.getParent() लिखा आप LinearLayout

पर सीधे
if(((LinearLayout) linearLayout).getChildCount() > 0) 
    ((LinearLayout) linearLayout).removeAllViews(); 
5

हाय कृपया इस कोड की कोशिश यह सब करना चाहिए इसकी मुझे

public class ShowText extends Activity { 
    /** Called when the activity is first created. */ 
    LinearLayout linearLayout; 
    TextView textView,textView1; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     textView=new TextView(this); 
     textView1=new TextView(this); 
     textView.setText("First TextView"); 
     textView1.setText("First TextView"); 

     linearLayout=(LinearLayout) findViewById(R.id.mn); 
     linearLayout.addView(textView); 
     linearLayout.addView(textView1); 
     linearLayout.removeAllViews(); 

    } 
} 
के लिए काम
संबंधित मुद्दे