当我尝试用一个替换Fragment
另一个时,我遇到了一些问题ViewPager
.
现在的情况
我有ViewPager
3页,每一页都是Fragment
.在第一页中,我有一个ListView
内部ListFragment
("FacturasFragment").当我点击该列表中的某个项目时,我使用onListItemClick
方法来处理该事件.
我想要的是
ListFragment
(包含发票列表)与另一个Fragment
("DetallesFacturaFragment",包含发票的详细信息).Button
,应该返回ListFragment
.Fragment
在第一个中显示.如果我在第一页上有"DetallesFacturaFragment"并滚动到第二页,当返回第一页时应继续显示"DetallesFacturaFragment".码
FragmentActivity
public class TabsFacturasActivity extends SherlockFragmentActivity {
private MyAdapter mAdapter;
private ViewPager mPager;
private PageIndicator mIndicator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
mAdapter = new MyAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
private static class MyAdapter extends FragmentPagerAdapter {
private String[] titles = …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android应用程序,我必须打开一些文件.
这是我使用intent的代码:
public class FacturaActivity extends Activity {
(...)
public void downloadInvoice(View view) {
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
文件位于SD卡的根目录中,我可以手动打开它.
问题
应用程序在到达startActivity(intent)时关闭.我认为问题出在AndroidManifest.xml文件中,但我不知道如何正确使用它.
AndroidManifest.xml中
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="###.MyApplication" > <!--cant show complete name-->
<activity
android:name="###.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FacturaActivity" >
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
logcat的
07-03 15:49:13.094: E/AndroidRuntime(1032): FATAL EXCEPTION: …
Run Code Online (Sandbox Code Playgroud) 我正在ViewPager
使用3 Fragments
并且我想要更改TextView
第三页的文本.
在那个页面中我有一个Button
按下时,转到SD图像选择一个.完成后,返回页面并希望TextView
使用该图像的路径进行更新.问题是,当我尝试访问它时TextView
,FragmentActivity
它是null.
这是我的代码
SherlockFragmentActivity:
public class TabsFacturasActivity extends SherlockFragmentActivity {
protected MyApplication myApplication;
private static final int FILE_SELECT_CODE = 0;
private MyAdapter mAdapter;
private ViewPager mPager;
private PageIndicator mIndicator;
private TextView textViewImg;
private int lecturas = 0;
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
private boolean adjunto = false;
private String filePath;
private boolean esLecturaAT = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
// Get …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个必须从Web服务下载一些文件的Android应用程序.
目标
我想从网络服务下载PDF文件并在手机上显示.
问题
我是新手使用webservices并且我已经非常清楚如何获取文件并打开它.
这是我迄今为止的代码:
public void downloadFile(String username, String password, String filename) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("filename", filename));
String output = httpPost(URL_DESCARGAS, nameValuePairs);
}
private String httpPost(String url, List<NameValuePair> nameValuePairs) {
/* Create new HttpClient and Post Header */
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
/* Get output */
return inputStreamToString(response.getEntity().getContent()).toString(); …
Run Code Online (Sandbox Code Playgroud) 我有两个表“Persona”(人)和“Dona”(女性),我想更改第三个名为“Baptisme”(洗礼)的表,但我遇到了一些问题。
这些是我的表:
CREATE TABLE baptismes.Persona (
id SERIAL PRIMARY KEY,
nom VARCHAR(255),
nom_complementari1 VARCHAR(255),
nom_complementari2 VARCHAR(255),
nom_complementari3 VARCHAR(255),
nom_complementari4 VARCHAR(255),
cognom1 VARCHAR(255),
cognom2 VARCHAR(255),
lloc_naixement VARCHAR(255) REFERENCES baptismes.Poblacio(nom),
data_naixement baptismes.Data,
alies VARCHAR(255),
sexe CHAR(1),
difunt BOOLEAN
);
CREATE TABLE baptismes.Dona (
cognom_marit_actual VARCHAR(255),
cognom_marit_anterior VARCHAR(255)
) INHERITS (baptismes.Persona);
CREATE TABLE baptismes.Baptisme (
id SERIAL PRIMARY KEY,
...
);
Run Code Online (Sandbox Code Playgroud)
Baptisme 具有更多属性,但它们在这里无关紧要。
我想要做的是:
ALTER TABLE baptismes.baptisme
ADD COLUMN mare INTEGER REFERENCES baptismes.Dona(id);
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误:
ERROR: no hay restricción unique que coincida con las …
Run Code Online (Sandbox Code Playgroud) android ×4
file ×2
pdf ×2
http-post ×1
listview ×1
postgresql ×1
sql ×1
textview ×1
web-services ×1