Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > Mobile > Mobile Forum > อยากทราบว่า สามารถ extend 2 class ได้ไหมครับ Fragment กับ Activity


[Mobile] อยากทราบว่า สามารถ extend 2 class ได้ไหมครับ Fragment กับ Activity

 
Topic : 094003



โพสกระทู้ ( 51 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์



คือมีจะทำ viewpager swipe อ่ะครับ มันต้อง extend fragment

แล้วจะใส่โค้ดไปในหน้านั้นด้วย จะต้อง extend Activity อีกทีครับ ไม่ทราบว่าจะมี การรวมโค้ดเข้าด้วยกันได้อย่างไรครับ

อันนี้โค้ด ที่ extend fragment

Code (Android-Java)
01.public class Tab1Fragment extends Fragment {
02.    /** (non-Javadoc)
03.     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
04.     */
05.    public View onCreateView(LayoutInflater inflater, ViewGroup container,
06.            Bundle savedInstanceState) {
07.        if (container == null) {
08.            // We have different layouts, and in one of them this
09.            // fragment's containing frame doesn't exist.  The fragment
10.            // may still be created from its saved state, but there is
11.            // no reason to try to create its view hierarchy because it
12.            // won't be displayed.  Note this is not needed -- we could
13.            // just run the code below, where we would create and return
14.            // the view hierarchy; it would just never be used.
15.            return null;
16.        }
17.        return (LinearLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false);
18.    }
19.}


อันนีเโค้ดที่ extend Activity
Code (Android-Java)
001.package com.travel;
002. 
003.import java.io.BufferedReader;
004.import java.io.FileNotFoundException;
005.import java.io.IOException;
006.import java.io.InputStream;
007.import java.io.InputStreamReader;
008.import java.net.MalformedURLException;
009.import java.util.ArrayList;
010.import java.util.List;
011. 
012.import org.apache.http.HttpEntity;
013.import org.apache.http.HttpResponse;
014.import org.apache.http.NameValuePair;
015.import org.apache.http.StatusLine;
016.import org.apache.http.client.ClientProtocolException;
017.import org.apache.http.client.HttpClient;
018.import org.apache.http.client.entity.UrlEncodedFormEntity;
019.import org.apache.http.client.methods.HttpPost;
020.import org.apache.http.impl.client.DefaultHttpClient;
021.import org.apache.http.message.BasicNameValuePair;
022.import org.json.JSONException;
023.import org.json.JSONObject;
024. 
025.import com.travel.AsyncFacebookRunner.RequestListener;
026.import com.travel.SessionEvents.AuthListener;
027.import com.travel.SessionEvents.LogoutListener;
028. 
029.import android.os.Bundle;
030.import android.os.StrictMode;
031.import android.annotation.SuppressLint;
032.import android.app.Activity;
033.import android.app.AlertDialog;
034.import android.content.Intent;
035.import android.content.SharedPreferences;
036.import android.content.SharedPreferences.Editor;
037.import android.support.v4.app.Fragment;
038.import android.util.Log;
039.import android.view.LayoutInflater;
040.import android.view.View;
041.import android.view.ViewGroup;
042.import android.view.View.OnClickListener;
043.import android.widget.Button;
044.import android.widget.LinearLayout;
045.import android.widget.TextView;
046. 
047. 
048. 
049.public class show_menu extends Activity implements OnClickListener {
050.     
051.    private static final String tag = "show_menu";
052.    private LoginButton mLoginButton;
053.    String name;
054.    String id;
055.    String idName;
056.    private Facebook mFacebook;
057.    private AsyncFacebookRunner mAsyncRunner;
058.    private TextView txtLogin;
059.    private TextView txtLoginID;
060.     
061.    @SuppressLint("NewApi")
062.    @Override
063.    public void onCreate(Bundle savedInstanceState) {
064.        super.onCreate(savedInstanceState);
065.        Log.d(tag, getResources().getString(R.string.CREATING_VIEW));
066.        mFacebook = new Facebook(getResources().getString(R.string.FACEBOOK_ID_TEST));
067.        setContentView(R.layout.show_menu);
068.             
069.         
070.        // Permission StrictMode
071.        if (android.os.Build.VERSION.SDK_INT > 9) {
072.            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
073.            StrictMode.setThreadPolicy(policy);
074.        }
075.         
076.        SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
077.        Editor editor = pref.edit();
078.        String status = pref.getString("status", "");
079.         
080.//        Intent intent= getIntent();
081.//        String status = intent.getStringExtra("status");
082.//        String MemberID = intent.getStringExtra("MemberID");
083.         
084.        mLoginButton = (LoginButton) this.findViewById(R.id.login);
085.        txtLogin = (TextView) this.findViewById(R.id.txtShowName);
086.        txtLoginID = (TextView) this.findViewById(R.id.txtLoginID);
087.         
088.//      txtLogin.setText(status);
089.         
090.        if(status == "userLogin"){
091.            txtLogin.setText(status);
092.            //txtLoginID.setText(MemberID);
093.            editor.putString("status", status.toString().trim());
094.            editor.commit();
095.        }
096.        else if(status == "facebookLogin"){
097.            txtLogin.setText(status);
098.            //txtLoginID.setText(strMemberID);
099.            editor.putString("status", status.toString().trim());
100.            editor.commit();
101.            mAsyncRunner = new AsyncFacebookRunner(mFacebook);
102.            mAsyncRunner.request("me", new SampleRequestListener());
103.        }
104.         
105.        //
106.        //mAsyncRunner = new AsyncFacebookRunner(mFacebook);
107.        //mAsyncRunner.request("me", new SampleRequestListener());
108. 
109. 
110.        SessionStore.restore(mFacebook, this);
111.        SessionEvents.addAuthListener(new SampleAuthListener());
112.        SessionEvents.addLogoutListener(new SampleLogoutListener());
113.        mLoginButton.init(this, mFacebook);
114.     
115.        // btnDetailMember
116.        Button btnDetailMember = (Button) findViewById(R.id.btnDetailMember);
117.        btnDetailMember.setOnClickListener(new OnClickListener() {
118.            @Override
119.            public void onClick(View v) {
120.                Intent newActivity = new Intent(show_menu.this,DetailMember.class);
121.                finish();
122.                startActivity(newActivity);
123.            }
124.        });
125.         
126.        // btnLogOut
127.        Button btnLogout = (Button) findViewById(R.id.btnLogout);
128.        btnLogout.setOnClickListener(new OnClickListener() {
129.            @Override
130.            public void onClick(View v) {
131.                SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
132.                Editor editor = pref.edit();
133.                String status = pref.getString("status", "");
134.                 
135.                if(status == "userLogin"){
136.                    editor.clear();
137.                    editor.commit();
138.                    Intent newActivity = new Intent(show_menu.this,Main.class);
139.                    finish();
140.                    startActivity(newActivity);
141.                }
142.                else{
143.                    mLoginButton.performClick();
144.                }
145. 
146.            }
147.        });
148.         
149.        // btnMenuAdmin
150.        Button btnAdmin = (Button) findViewById(R.id.btnAdmin);
151.        btnAdmin.setOnClickListener(new OnClickListener() {
152.            @Override
153.            public void onClick(View v) {
154.                Intent newActivity = new Intent(show_menu.this,Main_tab.class);
155.                finish();
156.                startActivity(newActivity);
157.            }
158.        });
159.         
160.         
161.    }
162.    @Override
163.    public void onActivityResult(int requestCode, int resultCode, Intent data)
164.        {
165.            super.onActivityResult(requestCode, resultCode, data);
166.            mFacebook.authorizeCallback(requestCode, resultCode, data);
167.        }
168. 
169.    //
170.    public class SampleAuthListener implements AuthListener
171.        {
172. 
173.            @Override
174.            public void onAuthSucceed()
175.                {
176.//                  Intent intent = new Intent(Main.this,show_menu.class);
177.//                  startActivity(intent);
178.                }
179. 
180.            @Override
181.            public void onAuthFail(String error)
182.                {
183.                 
184.                }
185.        }
186. 
187.    public class SampleLogoutListener implements LogoutListener
188.        {
189.            @Override
190.            public void onLogoutBegin()
191.                {
192.                 
193.                }
194. 
195.            @Override
196.            public void onLogoutFinish()
197.                {
198.                    Intent intent = new Intent(show_menu.this,Main.class);
199.                    finish();
200.                    startActivity(intent);
201.                }
202.        }
203. 
204.    public class SampleRequestListener extends BaseRequestListener
205.        {
206. 
207.            @Override
208.            public void onComplete(final String response, final Object state)
209.                {
210.                    try
211.                        {
212.                            // process the response here: executed in background thread
213.                            Log.d("Facebook-Example", "Response: " + response.toString());
214.                            JSONObject json = Util.parseJson(response);
215.                            name = json.getString("name");
216.                            id = json.getString("id");
217. 
218.                            // then post the processed result back to the UI thread
219.                            // if we do not do this, an runtime exception will be generated
220.                            // e.g. "CalledFromWrongThreadException: Only the original
221.                            // thread that created a view hierarchy can touch its views."
222.                            show_menu.this.runOnUiThread(new Runnable()
223.                                {
224.                                    @Override
225.                                    public void run()
226.                                        {
227.                                          //txtLogin.setText("Hello there, " + name);
228.                                          txtLoginID.setText(id);
229.                                        }
230.                                });
231.                        }
232.                    catch (JSONException e)
233.                        {
234.                            Log.w("Facebook-Example", "JSON Error in response");
235.                        }
236.                    catch (FacebookError e)
237.                        {
238.                            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
239.                        }
240.                }
241.        }
242. 
243.    public class SampleUploadListener extends BaseRequestListener
244.        {
245. 
246.            @Override
247.            public void onComplete(final String response, final Object state)
248.                {
249.                    try
250.                        {
251.                            // process the response here: (executed in background thread)
252.                            Log.d("Facebook-Example", "Response: " + response.toString());
253.                            JSONObject json = Util.parseJson(response);
254.                            final String src = json.getString("src");
255. 
256.                            // then post the processed result back to the UI thread
257.                            // if we do not do this, an runtime exception will be generated
258.                            // e.g. "CalledFromWrongThreadException: Only the original
259.                            // thread that created a view hierarchy can touch its views."
260.                            show_menu.this.runOnUiThread(new Runnable()
261.                                {
262.                                    @Override
263.                                    public void run()
264.                                        {
265.                                         
266.                                        }
267.                                });
268.                        }
269.                    catch (JSONException e)
270.                        {
271.                            Log.w("Facebook-Example", "JSON Error in response");
272.                        }
273.                    catch (FacebookError e)
274.                        {
275.                            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
276.                        }
277.                }
278.        }
279. 
280.    public class WallPostRequestListener extends BaseRequestListener
281.        {
282. 
283.            @Override
284.            public void onComplete(final String response, final Object state)
285.                {
286.                    Log.d("Facebook-Example", "Got response: " + response);
287.                    String message = "<empty>";
288.                    try
289.                        {
290.                            JSONObject json = Util.parseJson(response);
291.                            message = json.getString("message");
292.                        }
293.                    catch (JSONException e)
294.                        {
295.                            Log.w("Facebook-Example", "JSON Error in response");
296.                        }
297.                    catch (FacebookError e)
298.                        {
299.                            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
300.                        }
301.                    final String text = "Your Wall Post: " + message;
302.                    show_menu.this.runOnUiThread(new Runnable()
303.                        {
304.                            @Override
305.                            public void run()
306.                                {
307.                                 
308.                                }
309.                        });
310.                }
311.        }
312. 
313.    public class WallPostDeleteListener extends BaseRequestListener
314.        {
315. 
316.            @Override
317.            public void onComplete(final String response, final Object state)
318.                {
319.                    if (response.equals("true"))
320.                        {
321.                            Log.d("Facebook-Example", "Successfully deleted wall post");
322.                            show_menu.this.runOnUiThread(new Runnable()
323.                                {
324.                                    @Override
325.                                    public void run()
326.                                        {
327.                                         
328.                                        }
329.                                });
330.                        }
331.                    else
332.                        {
333.                            Log.d("Facebook-Example", "Could not delete wall post");
334.                        }
335.                }
336.        }
337. 
338.    public class SampleDialogListener extends BaseDialogListener
339.        {
340. 
341.            @Override
342.            public void onComplete(Bundle values)
343.                {
344.                    final String postId = values.getString("post_id");
345.                    if (postId != null)
346.                        {
347.                            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
348.                            mAsyncRunner.request(postId, new WallPostRequestListener());
349.                             
350.                        }
351.                    else
352.                        {
353.                            Log.d("Facebook-Example", "No wall post made");
354.                        }
355.                }
356.        }
357. 
358.    /*
359.     * (non-Javadoc)
360.     *
361.     * @see android.view.View.OnClickListener#onClick(android.view.View)
362.     */
363.    public void onClick(View v)
364.        {
365. 
366.            if (v == mLoginButton)
367.                {
368. 
369.                }
370. 
371.             
372.        }
373.     
374.    public String getHttpPost(String url,List<NameValuePair> params) {
375.        StringBuilder str = new StringBuilder();
376.        HttpClient client = new DefaultHttpClient();
377.        HttpPost httpPost = new HttpPost(url);
378.         
379.        try {
380.            httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
381.            HttpResponse response = client.execute(httpPost);
382.            StatusLine statusLine = response.getStatusLine();
383.            int statusCode = statusLine.getStatusCode();
384.            if (statusCode == 200) { // Status OK
385.                HttpEntity entity = response.getEntity();
386.                InputStream content = entity.getContent();
387.                BufferedReader reader = new BufferedReader(new InputStreamReader(content));
388.                String line;
389.                while ((line = reader.readLine()) != null) {
390.                    str.append(line);
391.                }
392.            } else {
393.                Log.e("Log", "Failed to download result..");
394.            }
395.        } catch (ClientProtocolException e) {
396.            e.printStackTrace();
397.        } catch (IOException e) {
398.            e.printStackTrace();
399.        }
400.        return str.toString();
401.    }
402.     
403.    public void logoutFromFacebook() {
404.        mAsyncRunner.logout(this, new RequestListener() {
405.            @Override
406.            public void onComplete(String response, Object state) {
407.                Log.d("Logout from Facebook", response);
408.                if (Boolean.parseBoolean(response) == true) {
409.                    runOnUiThread(new Runnable() {
410. 
411.                        @Override
412.                        public void run() {
413. 
414.                        }
415. 
416.                    });
417. 
418.                }
419.            }
420. 
421.            @Override
422.            public void onIOException(IOException e, Object state) {
423.                // TODO Auto-generated method stub
424.                 
425.            }
426. 
427.            @Override
428.            public void onFileNotFoundException(FileNotFoundException e,
429.                    Object state) {
430.                // TODO Auto-generated method stub
431.                 
432.            }
433. 
434.            @Override
435.            public void onMalformedURLException(MalformedURLException e,
436.                    Object state) {
437.                // TODO Auto-generated method stub
438.                 
439.            }
440. 
441.            @Override
442.            public void onFacebookError(FacebookError e, Object state) {
443.                // TODO Auto-generated method stub
444.                 
445.            }
446. 
447.        });
448.    }
449.     
450.     
451.}


ขอบคุณครับ



Tag : Mobile, Android

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-04-21 14:59:52 By : nutsai4 View : 3948 Reply : 1
 

 

No. 1



โพสกระทู้ ( 51 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มีใครพอจะทราบไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-23 19:05:40 By : nutsai4
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบว่า สามารถ extend 2 class ได้ไหมครับ Fragment กับ Activity
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่