Hỏi về cách chuyển giao diện app android từ điện thoại sang tablet?
Thân chào mọi người,
Mình đang học android, cũng được một thời gian ngắn. Hiện mình đang găp vấn đề về việc chuyển giao diện từ điện thoại qua tablet.
Đây là giao diện ban đầu trên điện thoại:
Main activity:
Detail activiy (Sau khi click vào để xem chi tiêt
Đây là giao diện mình muốn sẽ xuất hiện trên tablet, tức là kết hợp cả Main Activity và Detail Activity xuất hiện cùng một lúc:
Nhưng kết quả lại ra thế này:
Uploading…
Không thấy báo một lỗi nào cả. Đây là code phần main activity của mình, các bạn xem rồi giúp mình với nhé. Xin cảm ơn.
package com.example.android.sunshine.app;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
//public class MainActivity extends ActionBarActivity {
public class MainActivity extends ActionBarActivity implements ForecastFragment.Callback {
private final String LOG_TAG = MainActivity.class.getSimpleName();
// private final String FORECASTFRAGMENT_TAG = "FFTAG";
private static final String DETAILFRAGMENT_TAG = "DFTAG";
private boolean mTwoPane;
private String mLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
// mLocation = Utility.getPreferredLocation(this);
super.onCreate(savedInstanceState);
mLocation = Utility.getPreferredLocation(this);
setContentView(R.layout.activity_main);
// if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
//// .add(R.id.container, new ForecastFragment())
// .add(R.id.container, new ForecastFragment(), FORECASTFRAGMENT_TAG)
// .commit();
if (findViewById(R.id.weather_detail_container) != null) {
// The detail container view will be present only in the large-screen layouts
// (res/layout-sw600dp). If this view is present, then the activity should be
// in two-pane mode.
mTwoPane = true;
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
.commit();
}
} else {
mTwoPane = false;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
}
if (id == R.id.action_map) {
openPreferredLocationInMap();
return true;
}
return super.onOptionsItemSelected(item);}
private void openPreferredLocationInMap() {
// SharedPreferences sharedPrefs =
// PreferenceManager.getDefaultSharedPreferences(this);
// String location = sharedPrefs.getString(
// getString(R.string.pref_location_key),
// getString(R.string.pref_location_default));
String location = Utility.getPreferredLocation(this);
// Using the URI scheme for showing a location found on a map. This super-handy
// intent can is detailed in the "Common Intents" page of Android's developer site:
// http://developer.android.com/guide/components/intents-common.html#Maps
Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
.appendQueryParameter("q", location)
.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(LOG_TAG, "Couldn't call " + location + ", no receiving apps installed!");
}
}
@Override
protected void onResume() {
super.onResume();
String location = Utility.getPreferredLocation( this );
// update the location in our second pane using the fragment manager
// if (location != null && !location.equals(mLocation)) {
// ForecastFragment ff = (ForecastFragment)getSupportFragmentManager().findFragmentByTag(FORECASTFRAGMENT_TAG);
if (location != null && !location.equals(mLocation)) {
ForecastFragment ff = (ForecastFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_forecast);
if ( null != ff ) {
ff.onLocationChanged();
}
DetailFragment df = (DetailFragment)getSupportFragmentManager().findFragmentByTag(DETAILFRAGMENT_TAG);
if ( null != df ) {
df.onLocationChanged(location);
}
mLocation = location;
}
}
@Override
public void onItemSelected(Uri contentUri) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
Bundle args = new Bundle();
args.putParcelable(DetailFragment.DETAIL_URI, contentUri);
DetailFragment fragment = new DetailFragment();
fragment.setArguments(args);
getSupportFragmentManager().beginTransaction()
.replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG)
.commit();
} else {
Intent intent = new Intent(this, DetailActivity.class)
.setData(contentUri);
startActivity(intent);
}
}
}
/**
* A placeholder fragment containing a simple view.
*/