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,027

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



 

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

 



Topic : 094003



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

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

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




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

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

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

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



อันนีเโค้ดที่ extend Activity
Code (Android-Java)
package com.travel;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import com.travel.AsyncFacebookRunner.RequestListener;
import com.travel.SessionEvents.AuthListener;
import com.travel.SessionEvents.LogoutListener;

import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;



public class show_menu extends Activity implements OnClickListener {
	
	private static final String tag = "show_menu";
	private LoginButton mLoginButton;
	String name;
	String id;
	String idName;
	private Facebook mFacebook;
	private AsyncFacebookRunner mAsyncRunner;
	private TextView txtLogin;
	private TextView txtLoginID;
    
    @SuppressLint("NewApi")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(tag, getResources().getString(R.string.CREATING_VIEW));
		mFacebook = new Facebook(getResources().getString(R.string.FACEBOOK_ID_TEST));
        setContentView(R.layout.show_menu);
        	
        
        // Permission StrictMode
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        
        SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
        Editor editor = pref.edit();
        String status = pref.getString("status", "");
        
//        Intent intent= getIntent();
//        String status = intent.getStringExtra("status"); 
//        String MemberID = intent.getStringExtra("MemberID"); 
        
        mLoginButton = (LoginButton) this.findViewById(R.id.login);
        txtLogin = (TextView) this.findViewById(R.id.txtShowName);
        txtLoginID = (TextView) this.findViewById(R.id.txtLoginID);
        
//    	txtLogin.setText(status);
        
        if(status == "userLogin"){
        	txtLogin.setText(status);
        	//txtLoginID.setText(MemberID);
            editor.putString("status", status.toString().trim());
            editor.commit();
        }
        else if(status == "facebookLogin"){
        	txtLogin.setText(status);
            //txtLoginID.setText(strMemberID);
        	editor.putString("status", status.toString().trim());
        	editor.commit();
        	mAsyncRunner = new AsyncFacebookRunner(mFacebook);
    		mAsyncRunner.request("me", new SampleRequestListener());
        }
        
        //
		//mAsyncRunner = new AsyncFacebookRunner(mFacebook);
		//mAsyncRunner.request("me", new SampleRequestListener());


		SessionStore.restore(mFacebook, this);
		SessionEvents.addAuthListener(new SampleAuthListener());
		SessionEvents.addLogoutListener(new SampleLogoutListener());
		mLoginButton.init(this, mFacebook);
	
		// btnDetailMember
        Button btnDetailMember = (Button) findViewById(R.id.btnDetailMember);
        btnDetailMember.setOnClickListener(new OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        	Intent newActivity = new Intent(show_menu.this,DetailMember.class);
	        	finish();
				startActivity(newActivity);
	        }
	    });
        
        // btnLogOut
        Button btnLogout = (Button) findViewById(R.id.btnLogout);
        btnLogout.setOnClickListener(new OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        	SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
	            Editor editor = pref.edit();
	            String status = pref.getString("status", "");
	            
	            if(status == "userLogin"){
	            	editor.clear();
		        	editor.commit();
		        	Intent newActivity = new Intent(show_menu.this,Main.class);
		        	finish();
					startActivity(newActivity);
	            }
	            else{
	            	mLoginButton.performClick();
	            }

	        }
	    });
        
        // btnMenuAdmin
        Button btnAdmin = (Button) findViewById(R.id.btnAdmin);
        btnAdmin.setOnClickListener(new OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        	Intent newActivity = new Intent(show_menu.this,Main_tab.class);
	        	finish();
				startActivity(newActivity);
	        }
	    });
        
        
    }
    @Override
	public void onActivityResult(int requestCode, int resultCode, Intent data)
		{
			super.onActivityResult(requestCode, resultCode, data);
			mFacebook.authorizeCallback(requestCode, resultCode, data);
		}

	//
	public class SampleAuthListener implements AuthListener
		{

			@Override
			public void onAuthSucceed()
				{
//					Intent intent = new Intent(Main.this,show_menu.class);
//					startActivity(intent);
				}

			@Override
			public void onAuthFail(String error)
				{
				
				}
		}

	public class SampleLogoutListener implements LogoutListener
		{
			@Override
			public void onLogoutBegin()
				{
				
				}

			@Override
			public void onLogoutFinish()
				{
					Intent intent = new Intent(show_menu.this,Main.class);
					finish();
					startActivity(intent);
				}
		}

	public class SampleRequestListener extends BaseRequestListener
		{

			@Override
			public void onComplete(final String response, final Object state)
				{
					try
						{
							// process the response here: executed in background thread
							Log.d("Facebook-Example", "Response: " + response.toString());
							JSONObject json = Util.parseJson(response);
							name = json.getString("name");
							id = json.getString("id");

							// then post the processed result back to the UI thread
							// if we do not do this, an runtime exception will be generated
							// e.g. "CalledFromWrongThreadException: Only the original
							// thread that created a view hierarchy can touch its views."
							show_menu.this.runOnUiThread(new Runnable()
								{
									@Override
									public void run()
										{
										  //txtLogin.setText("Hello there, " + name);
										  txtLoginID.setText(id);
										}
								});
						}
					catch (JSONException e)
						{
							Log.w("Facebook-Example", "JSON Error in response");
						}
					catch (FacebookError e)
						{
							Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
						}
				}
		}

	public class SampleUploadListener extends BaseRequestListener
		{

			@Override
			public void onComplete(final String response, final Object state)
				{
					try
						{
							// process the response here: (executed in background thread)
							Log.d("Facebook-Example", "Response: " + response.toString());
							JSONObject json = Util.parseJson(response);
							final String src = json.getString("src");

							// then post the processed result back to the UI thread
							// if we do not do this, an runtime exception will be generated
							// e.g. "CalledFromWrongThreadException: Only the original
							// thread that created a view hierarchy can touch its views."
							show_menu.this.runOnUiThread(new Runnable()
								{
									@Override
									public void run()
										{
										
										}
								});
						}
					catch (JSONException e)
						{
							Log.w("Facebook-Example", "JSON Error in response");
						}
					catch (FacebookError e)
						{
							Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
						}
				}
		}

	public class WallPostRequestListener extends BaseRequestListener
		{

			@Override
			public void onComplete(final String response, final Object state)
				{
					Log.d("Facebook-Example", "Got response: " + response);
					String message = "<empty>";
					try
						{
							JSONObject json = Util.parseJson(response);
							message = json.getString("message");
						}
					catch (JSONException e)
						{
							Log.w("Facebook-Example", "JSON Error in response");
						}
					catch (FacebookError e)
						{
							Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
						}
					final String text = "Your Wall Post: " + message;
					show_menu.this.runOnUiThread(new Runnable()
						{
							@Override
							public void run()
								{
								
								}
						});
				}
		}

	public class WallPostDeleteListener extends BaseRequestListener
		{

			@Override
			public void onComplete(final String response, final Object state)
				{
					if (response.equals("true"))
						{
							Log.d("Facebook-Example", "Successfully deleted wall post");
							show_menu.this.runOnUiThread(new Runnable()
								{
									@Override
									public void run()
										{
										
										}
								});
						}
					else
						{
							Log.d("Facebook-Example", "Could not delete wall post");
						}
				}
		}

	public class SampleDialogListener extends BaseDialogListener
		{

			@Override
			public void onComplete(Bundle values)
				{
					final String postId = values.getString("post_id");
					if (postId != null)
						{
							Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
							mAsyncRunner.request(postId, new WallPostRequestListener());
							
						}
					else
						{
							Log.d("Facebook-Example", "No wall post made");
						}
				}
		}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	public void onClick(View v)
		{

			if (v == mLoginButton)
				{

				}

			
		}
	
	public String getHttpPost(String url,List<NameValuePair> params) {
		StringBuilder str = new StringBuilder();
		HttpClient client = new DefaultHttpClient();
		HttpPost httpPost = new HttpPost(url);
		
		try {
			httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
			HttpResponse response = client.execute(httpPost);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) { // Status OK
				HttpEntity entity = response.getEntity();
				InputStream content = entity.getContent();
				BufferedReader reader = new BufferedReader(new InputStreamReader(content));
				String line;
				while ((line = reader.readLine()) != null) {
					str.append(line);
				}
			} else {
				Log.e("Log", "Failed to download result..");
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str.toString();
	}
	
	public void logoutFromFacebook() {
	    mAsyncRunner.logout(this, new RequestListener() {
	        @Override
	        public void onComplete(String response, Object state) {
	            Log.d("Logout from Facebook", response);
	            if (Boolean.parseBoolean(response) == true) {
	                runOnUiThread(new Runnable() {

	                    @Override
	                    public void run() {

	                    }

	                });

	            }
	        }

			@Override
			public void onIOException(IOException e, Object state) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onFileNotFoundException(FileNotFoundException e,
					Object state) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onMalformedURLException(MalformedURLException e,
					Object state) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onFacebookError(FacebookError e, Object state) {
				// TODO Auto-generated method stub
				
			}

	    });
	}
    
    
}



ขอบคุณครับ



Tag : Mobile, Android







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-04-21 14:59:52 By : nutsai4 View : 3848 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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