नहीं बढ़ रहा है मैं xml के माध्यम से अपना कस्टम व्यू बनाने की कोशिश कर रहा हूं, लेकिन स्क्रीन मेरे दृश्य को नहीं दिखाती है, यह फुला नहीं रही है। के रूप मेंकस्टम व्यू
<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/profileSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imgAdvertise"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@android:drawable/btn_minus" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/txtAdvertise"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="asdas" />
</LinearLayout>
</ViewSwitcher>
मैं अपने कस्टम View
वर्ग है:: मेरे कस्टम दृश्य एक्सएमएल के रूप में है
public class MyCustomView extends View{
TextView textAdvertise;
ImageView imageAdvertise;
View view;
ViewSwitcher switcher ;
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (layoutInflater != null) {
view = layoutInflater.inflate(R.layout.main, null);
}
initialize();
}
public void initialize() {
// TODO Auto-generated method stub
textAdvertise = (TextView) view.findViewById(R.id.txtAdvertise);
imageAdvertise = (ImageView) view.findViewById(R.id.imgAdvertise);
switcher = (ViewSwitcher) view.findViewById(R.id.profileSwitcher);
startAnimation();
}
public void startAnimation() {
// TODO Auto-generated method stub
new Thread() {
public void run() {
for (;;) {
try {
Thread.sleep(2000);
hRefresh.sendEmptyMessage(5);
} catch (Exception e) {
}
}
}
}.start();
}
Handler hRefresh = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 5:
switcher.showNext();
// To go back to the first view, use switcher.showPrevious()
break;
default:
break;
}
}
};
}
और मेरे आधार XML लेआउट में मैं View
दिखाने के लिए जहां, एक बटन और और मेरे View
है के रूप में:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Button"
android:layout_weight="1"/>
<com.example.viewswitcher.MyCustomView
android:id="@+id/MyView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
किसी को भी कर सकते हैं कृपया मुझे बताओ कि यह क्या गलत हो रहा है?
हे मदद के लिए धन्यवाद .. यह काम किया .. असल में मेरे मेरे लेआउट inflator मैंने लिखा है = layoutInflater.inflate (आर .layout.main, शून्य); यह शून्य समस्या का कारण बनता है .. इसके बजाय मैंने "यह" रखा यह काम किया .. धन्यवाद दोस्त !! – NullPointerException
आपने जो प्रश्न संपादित किया है ... और एक और बात यह काम करती है क्योंकि मैंने देखने के बजाए लीनियरलाउट बढ़ाया है .. ऐसा क्यों ?? इस विवरण के बारे में कोई भी लिंक या पोस्ट .. धन्यवाद – NullPointerException
@ रश्मी मैंने आपके प्रश्न को कोड के कोड को बेहतर प्रारूपित करने के लिए संपादित किया है। 'व्यू' क्लास एक 'व्यू' ऑब्जेक्ट का प्रतिनिधित्व करती है, यह बच्चों को 'फुटेज' स्वीकार नहीं करती है जैसे आप इसे 'inflate' विधि' में जोड़ना चाहते हैं (वास्तव में यदि आप 'inflate' विधि को देखते हैं दस्तावेज़ आप देखेंगे कि दूसरा पैरामीटर 'व्यू ग्रुप' है)। इसके बजाय 'व्यू ग्रुप' ('लीनियरलाउट' 'व्यू ग्रुप' का उप-वर्ग है)' व्यू 'का प्रतिनिधित्व करता है (वास्तव में यह सुपर क्लास' व्यू' का उप-वर्ग है) जो बच्चों के दृश्यों को स्वीकार करता है। मुझे कोई लिंक नहीं पता लेकिन आप 'व्यू' और 'व्यू ग्रुप' के लिए दस्तावेज़ देख सकते हैं। – Luksprog