我是Android开发的新手,并且一直关注Android网站上提供的教程.我目前正在阅读Views的教程部分,特别是Grid Views:Hello,Grid View Tutorial.
我无法理解如何通过适配器进行查看.我知道您必须覆盖适配器类中的getView()方法,并在此方法中定义视图的设置方式.我不明白getView()实际上被调用的地方是什么?也许我在这里有错误的心态,但在下面的代码中(网格视图教程)我没有看到任何对getView()的调用(或适配器类中使用的任何其他东西,如getCount()) .
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" />
Run Code Online (Sandbox Code Playgroud)
Start.java
package com.examples.hellogridlayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Start extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView)findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View v, int position, long …Run Code Online (Sandbox Code Playgroud) 我的android布局如下:
<RelativeLayout>
<Layout
android:id="@+id/login_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.test.console.LoginFragment" />
<Layout
android:id="@+id/transperent_fragment"
android:name="com.test.transperentFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/body_texture"
android:alpha="0.2"> />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

如果我触摸透明层仍然点击登录按钮.那么触摸透明布局后如何避免登录按钮点击
有没有人知道如何在Android中打开PDF文件?我的代码看起来像这样:
public class SampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CopyReadAssets();
}
private void CopyReadAssets() {
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), "git.pdf");
try {
in = assetManager.open("git.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/git.pdf"),
"application/pdf");
startActivity(intent); …Run Code Online (Sandbox Code Playgroud) 我在getView中使用此代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listrow, null);
}
Order o = items.get(position);
if (o != null) {
TextView tt = (TextView) v.findViewById(R.id.toptext);
ImageView thumb = (ImageView) v.findViewById(R.id.icon);
if (o.getOrderDrawable() != null) {
thumb.setImageDrawable(o.getOrderDrawable());
} else {
tt.setText(o.getOrderTitle());
}
}
return v;
}
Run Code Online (Sandbox Code Playgroud)
问题是滚动时; 有时会显示正确的图像,但有时向后/向前滚动时,图像会随机显示,并且与行无关.
图像从网上下载.
我该如何解决这个问题?
我有一个从对话框扩展的自定义Dialog.为了在其上放置组件,我需要知道对话框的宽度.我怎么能这样做?谢谢
编辑:
public class AnswerTypeDialog extends Dialog{
public AnswerTypeDialog(Context context) {
super(context);
mContext = context;
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
protected void init(){
ll=(RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.answertype_layout, null);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(ll);
mWindowWidth = this.getWindow().getAttributes().width;
}
}
Run Code Online (Sandbox Code Playgroud)
mWindowWidth为零.
我正在创建一个AlertDialog.如果像这样创建它:
AlertDialog.Builder builder = AlertDialog.Builder((RelationActivity)getContext());
builder.setMessage("No relations found.");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
((RelationActivity)getContext()).finish();
}
});
builder.create();
builder.show();
Run Code Online (Sandbox Code Playgroud)
结果如下:http://www.ozze.com.br/1.png
但是,如果我尝试设置主题,像这样:
AlertDialog.Builder builder = new AlertDialog.Builder(((RelationActivity)getContext()), android.R.style.Theme_Holo_Light_Dialog);
Run Code Online (Sandbox Code Playgroud)
结果如下:http://www.ozze.com.br/2.png
拜托,有人可以帮我解决这个问题吗?看起来在使用主题时,主题"围绕"警报对话框.
我使用webVIew读取本地HTML.HTML存储位置 资产项目
有些手机可以成功使用(三星...)有些手机不能(HTC nexus ......)
这是我的代码
public class MainActivity extends Activity {
private WebView wvBrowser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (wvBrowser.canGoBack() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
wvBrowser.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private void findViews() {
wvBrowser = (WebView) findViewById(R.id.Browser);
//wvBrowser.loadUrl(getString(R.string.googleUrl));
wvBrowser.getSettings().setSupportZoom(true);
wvBrowser.getSettings().setBuiltInZoomControls(true);
wvBrowser.loadUrl("file:///android_asset/ts.htm");
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在寻找这个答案的高低,我完全傻眼了.
我正在使用GA在我的Android应用中实现简单的点击和页面跟踪,通过GTM运行.所有我的"屏幕"都可以在GA中实时显示,但我无法让"事件"出现.
实际上我可以,但行为似乎非常离奇.如果我不包含"标签"和"值",我可以看到事件出现.但是,如果我添加它们(无论是常量还是数据层变量),所有事件都会停止.我已经确认了我想要的变量"Label"和"Value"正在通过,因为我创建了一个容器,其中这些值为"Category"和"Action",并且可以实时看到它们.
这让我觉得应用程序端实现完全没问题,但我的GTM中的标签存在问题.(显然不是触发器,因为它在预期时也起作用).
理想情况下,我想做这样的事情(变量是数据层变量):
但这不起作用.我看不到任何事件.
android google-analytics google-tag-manager google-analytics-firebase
我有一个ListView包含a 的自定义Button.此按钮的功能是删除按钮.每当用户单击此按钮时,将删除当前行.
onClickListener此按钮?提前致谢.
我是Android的新手,几乎没有任何关于EditText视图的工作,但我仍然收到一些EditText我必须使用的图像.
我EditText从官方Android开发者页面看到了类似的自定义对话框(图5).
如您所见,每个EditText中都有一些下划线.
首先我想,EditText有这样的下划线,是默认的View.但是当我试图制作这样的EditText组件时,我遇到问题,默认EditText没有任何下划线,它只是一个简单的矩形,里面没有任何图像......我试图让这个组件成为另一个背景(创建选择器xml文件) ,设置一些背景图像......没有任何作用.
请给我一些建议:如何制作带下划线的EditBox,以及那张图片EditText.
PS我正在使用10 API Level(2.3.3)和支持库来处理片段.
PSS对不起,提供的信息很少.我是Stackoverflow的新手,无法发布图片,超过2个超链接......
我需要使用以下代码将具有从活动A到目标B的意图的长(_id)传递给活动B:
Intent vip0= new Intent(this, PageSinglePlayerGuess.class);
vip0.putExtra("resid", (long) 1);
startActivity(vip0);
Run Code Online (Sandbox Code Playgroud)
并使用此方法在活动B中获取它(在onCreate()中调用):
public long getResId() {
Intent i= getIntent();
resid= i.getLongExtra("resid", 1);
Log.d("D", "Risorsa: " + resid);
return resid;
}
Run Code Online (Sandbox Code Playgroud)
ActB中的渣油很长.我收到此错误:
06-06 11:10:47.138: W/Bundle(538): Key resid expected Long but value was a java.lang.Integer. The default value 1 was returned.
06-06 11:10:47.158: W/Bundle(538): Attempt to cast generated internal exception:
06-06 11:10:47.158: W/Bundle(538): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
06-06 11:10:47.158: W/Bundle(538): at android.os.Bundle.getLong(Bundle.java:966)
06-06 11:10:47.158: W/Bundle(538): at android.content.Intent.getLongExtra(Intent.java:3874)
06-06 11:10:47.158: W/Bundle(538): …Run Code Online (Sandbox Code Playgroud) 曾几何时在神奇的土地上你可以MapView通过在它的构造函数中添加它来设置旧的API密钥.这很有帮助,因为我可以有以下几点:
mMapView = new MapView(getActivity(), Environment.GOOGLE_MAPS_API_KEY);
Run Code Online (Sandbox Code Playgroud)
这允许我有一个可以根据代码是否生产而改变的密钥(通过交换Environment包含许多其他可爱的东西).
查看新的Google地图API文档,代码和相关帖子似乎没有办法做到这一点或类似的东西.我确实有一个解决方法的想法,要求我将strings.xml文件读取AndroidManifest,我也像我一样交换,Environment但我宁愿只是一个"配置文件",而不是两个.
所以我的问题是:有没有办法以某种方式为这些新地图设置API密钥AndroidManifest?