在notifyDataSetChanged类的方法文档中BaseAdapter指出"通知附加的观察者基础数据已经改变,反映数据集的任何视图都应该刷新自己".
假设我更改了我的字符串数组中的第3个元素(数组数据ListView),"反映数据集的任何视图应该刷新自己"是什么意思?是否会通知列表视图中的第3个视图项?
此外,如何notifyDataSetChanged()与getView()有关?
android notify android-listview android-adapter android-view
我希望在视图完成重绘后得到通知,我要求它无效.如本回答所述,该invalidate()方法不会onDraw()立即调用View的UI,而是在主线程空闲之后执行的消息队列中调度重绘.
我想显示一个进度对话框,进行一些UI修改,然后在正确绘制视图时关闭对话框.是否有一些技巧可以让我知道何时绘制视图?也许通过继承视图,重写onDraw()方法?
简而言之,问题是我可以通过id找到我的元素,但它一直要求我将它转换为视图,我不能将它转换为我的对象名称类型.我不确定转换为查看是否是假设,但Android示例只是创建片段并添加它因此它没有在xml中定义.但关键是在示例中,对象不是类型视图.
更多信息:这可能是一个快速简便的解决方案.我有一个片段类,它包含我用代码创建的自定义视图(它是一种不断绘制的游戏).我在xml布局的左上角添加了片段.片段下面是按钮(在xml布局中定义).我有一个主要的活动,我想要一个包含我自定义视图的片段实例的句柄,这样当单击按钮时,片段中的一些变量会被更改,并且视图会被重绘.
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment android:name="com.example.dcubebluetooth"
android:id="@+id/lEDView1"
android:layout_width="400px"
android:layout_height="400px" />
<Button
android:id="@+id/layer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/lEDView1"
android:layout_marginTop="50px"
android:text="Layer1"
android:textSize="12dp" />
<Button
android:id="@+id/layer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/layer1"
android:layout_toRightOf="@id/layer1"
android:text="Layer2"
android:textSize="12dp" />
<Button
android:id="@+id/layer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/layer2"
android:layout_toRightOf="@id/layer2"
android:text="Layer3"
android:textSize="12dp" />
<Button
android:id="@+id/layer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/layer3"
android:layout_toRightOf="@id/layer3"
android:text="Layer4"
android:textSize="12dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
主要活动:
public class MainActivity extends Activity implements LEDGridFragment.TriggerBlueTooth{
Button l1;
Button l2;
Button l3;
Button l4;
BluetoothService bt;
LEDGridFragment gridUI;
@Override
protected void …Run Code Online (Sandbox Code Playgroud) 我有一个视图总是在屏幕上(在其他应用程序上),我不会接收触摸事件而不是将它们传递得更远.
来自运行的代码Service:
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
v.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "view touched", Toast.LENGTH_SHORT).show();
return false;
}
});
WindowManager localWindowManager = (WindowManager)getSystemService("window");
localWindowManager.addView(v, localLayoutParams);
Run Code Online (Sandbox Code Playgroud)
目前我还没有接触到.
嗨,我正在创建tabla App,
例如

它不应该在圆形外响应,但ImageView是Rectangle,因此它正在响应
我相信你能理解这个问题
ImageView是矩形但它的图像是圆形的,但我想检测仅在圆形图像上的点击...
我试图设置组件的可聚焦性,并找到了这两种方法,希望我可以使用它们使组件仅在用户触摸时才可聚焦,而不能通过编程方式请求:
myComponent.setFocusable(false);
myComponent.setFocusableInTouchMode(true);
Run Code Online (Sandbox Code Playgroud)
然后我查看了他们的文档:
public void setFocusable(布尔型可聚焦)
设置此视图是否可以接收焦点。将其设置为false还将确保该视图在触摸模式下无法聚焦。
public void setFocusableInTouchMode(布尔的focusableInTouchMode)
设置在触摸模式下此视图是否可以接收焦点。将其设置为true也将确保该视图可聚焦。
那么,如果隐式调用任何一个,则为什么要区分?
我已经更新了API 21,工具和附加功能,一些项目中的ActionBar变得不可见.我在下面的代码中做了这个,但app崩溃显示NullPointerException.
ActionBar actionBar = getActionBar();
actionBar.show();
Run Code Online (Sandbox Code Playgroud)
Logcat输出
02-23 18:03:36.269:E/AndroidRuntime(3327):FATAL EXCEPTION:main 02-23 18:03:36.269:E/AndroidRuntime(3327):进程:com.example.twaapp,PID:3327 02-23 18:03:36.269:E/AndroidRuntime(3327):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.twaapp/com.example.twaapp.MainActivity}:java.lang.NullPointerException 02-23 18: 03:36.269:E/AndroidRuntime(3327):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)02-23 18:03:36.269:E/AndroidRuntime(3327):at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2257)02-23 18:03:36.269:E/AndroidRuntime(3327):在android.app.ActivityThread.access $ 800(ActivityThread.java:139)02-23 18:03:36.269:E/AndroidRuntime(3327):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1210)02-23 18:03:36.269:E/AndroidRuntime(3327):在android.os.Handler.dispatchMessage(Handler.java) :102)02-23 18:03:36.269:E/AndroidRuntime(3327):在android.os.Looper.loop(Looper.java:136)02-23 18:03:36.269:E/AndroidRuntime(3327):在android.app.ActivityThread.main(ActivityThread.java:5086)02-23 18:03:36.269:E/AndroidRuntime(3327):at java. lang.reflect.Method.invokeNative(Native Method)02-23 18:03:36.269:E/AndroidRuntime(3327):at java.lang.reflect.Method.invoke(Method.java:515)02-23 18:03 :36.269:E/AndroidRuntime(3327):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)02-23 18:03:36.269:E/AndroidRuntime(3327):at com. android.internal.os.ZygoteInit.main(ZygoteInit.java:601)02-23 18:03:36.269:E/AndroidRuntime(3327):at dalvik.system.NativeStart.main(Native Method)02-23 18:03 :36.269:E/AndroidRuntime(3327):引起:java.lang.NullPointerException 02-23 18:03:36.269:E/AndroidRuntime(3327):at com.example.twaapp.MainActivity.onCreate(MainActivity.java:82 )02-23 18:03:36.269:E/AndroidRuntime(3327):在android.app.Activity.performCreate(Activity.java:5248)02-23 18:03:36.269:E/AndroidRuntime(3327):at android .app.Instrumentatio n.callActivityOnCreate(Instrumentation.java:1110)02-23 18:03:36.269:E/AndroidRuntime(3327):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)02-23 18:03:36.269: E/AndroidRuntime(3327):......还有11个
如何让AB可见?
我刚刚开始学习Android.我对XML中的布局几乎没有什么困惑
我在布局中定义的所有视图是否基本上都是膨胀的还是可选的?假设我在视图组中有两个不同的视图,但我想只使用第一个或仅第二个有条件.可能吗?
动态创建的视图如何处理layout.XML文件?
如果我希望收到的消息以红色显示并以黑色发送消息,我该怎么办?
我正在使用带有javascript界面的 WebView,有时当我loadUrl在webView上调用时,mWebView.getContext()返回null.
mWebView.post(new Runnable() { ...被执行吗?这段代码是否相关?
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
mWebView.loadUrl("javascript:...");
} else {
mWebView.post(new Runnable() {
public void run() {
mWebView.loadUrl("javascript:...");
}
});
}
Run Code Online (Sandbox Code Playgroud)我在使用TextDrawable时遇到了一个问题- 我希望为同一个用户显示相同的颜色 - int color2 = generator.getColor("user@gmail.com");在我的情况下使用userId作为键,但我得到的是所有人userId的相同颜色.我在ListView和现在的RecyclerView中尝试了这个,但总是相同的结果 - 我的所有联系人共享相同的颜色.
这是我的ContactsAdapter的代码:
@Override
public void onBindViewHolder(ContactsAdapter.ContactsViewHolder holder, int position) {
Contact contact = contactList.get(position);
holder.userName.setText(contact.getUserName());
TextDrawable.IBuilder builder = TextDrawable.builder()
.beginConfig()
.withBorder(0)
.toUpperCase()
.endConfig()
.round();
ColorGenerator generator = ColorGenerator.MATERIAL;
// generate random color
int color1 = generator.getRandomColor();
// generate color based on a key (same key returns the same color), useful for list/grid views
int color2 = generator.getColor(holder.getItemId());
//int color2 = generator.getColor("user@gmail.com");
TextDrawable textDrawable …Run Code Online (Sandbox Code Playgroud)