我正在探索RecyclerView
,我很惊讶地看到RecyclerView
它没有onItemClickListener()
.因为RecyclerView
延伸
android.view.ViewGroup
并ListView
扩展
android.widget.AbsListView
.不过,我解决我的问题写onClick
在我的RecyclerView.Adapter
:
public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
public TextView txtViewTitle;
public ImageView imgViewIcon;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.item_title);
imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.item_icon);
}
@Override
public void onClick(View v) {
}
}
Run Code Online (Sandbox Code Playgroud)
但我仍然想知道为什么谷歌被删除了onItemClickListener()
?
是否有性能问题或其他问题?
这可能是一个愚蠢的问题,但我不太了解Design lib.我遵循此参考创建下面的布局.当我滚动时,蓝色区域应该作为视差GridView
.但是当我滚动网格时,AppBarLayout中没有任何反应.
但这适用于NestedScrollView
和RecyclerView
以下是我的布局文件 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:background="#500403"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#122453"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<ImageView
android:id="@+id/backdrop1"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitCenter"
android:fitsSystemWindows="true"
android:layout_gravity="center"
android:src="@drawable/bar_offline"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#982223"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<GridView
android:id="@+id/grid"
android:numColumns="4"
android:background="#367723"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" …
Run Code Online (Sandbox Code Playgroud) java android coordinator-layout android-collapsingtoolbarlayout android-6.0-marshmallow
我正在使用EditText
消息.高度EditText
是200dp
.
问题是当我点击这个时EditText
,光标在中间闪烁EditText
,而我想光标应该在顶部闪烁EditText
.
我有非常基本的问题.它可能很简单,但我没有得到它.我有一个Activity,我正在使用一些UI组件.我还有一个广播接收器(从清单注册) ,我需要更新Activity类的一些UI组件.喜欢 -
Class MyActivity extends Activity
{
onCreate(){
//using some UI component lets say textview
textView.setText("Some Text");
}
updateLayout()
{
textView.setText("TextView Upadated...");
}
}
Class broadCastReceiver
{
onReceive()
{
//here I want to update My Activity component like
UpdateLayout();
}
}
Run Code Online (Sandbox Code Playgroud)
为此 - 一个解决方案是使updateLayout()方法公共静态,并通过活动引用在接收器类中使用该方法.但我认为,这不是正确的方法.有没有正确的方法来做到这一点?
我尝试Activity
在我的AsyncTask
班级(onPostExecute()
)中开始并关闭其他人.
我的代码:
Intent i = new Intent(parentActivity, ThunderHunter.class);
c.startActivity(i);
parentActivity.finish();
Run Code Online (Sandbox Code Playgroud)
但它不起作用,logcat显示:
08-01 18:01:27.640: E/AndroidRuntime(12398): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.app.ContextImpl.startActivity(ContextImpl.java:1029)
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.app.ContextImpl.startActivity(ContextImpl.java:1023)
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.content.ContextWrapper.startActivity(ContextWrapper.java:283)
08-01 18:01:27.640: E/AndroidRuntime(12398): at com.radzik.thunter.FunkcjeAPI$Logowanie.onPostExecute(FunkcjeAPI.java:151)
08-01 18:01:27.640: E/AndroidRuntime(12398): at com.radzik.thunter.FunkcjeAPI$Logowanie.onPostExecute(FunkcjeAPI.java:1)
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-01 18:01:27.640: E/AndroidRuntime(12398): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-01 …
Run Code Online (Sandbox Code Playgroud) android runtime-error android-intent android-asynctask android-activity
嗨,我正在开发Android Gallery应用程序.我从SD卡中的文件夹中获取图像并将其显示在网格视图中,如下所示
public static ArrayList<String> getFilePaths()
{
ArrayList<String> filePaths = new ArrayList<String>();
File directory = new File(android.os.Environment.getExternalStorageDirectory() + File.separator + AppConstant.PHOTO_ALBUM);
// check for directory
if (directory.isDirectory())
{
// getting list of file paths
File[] listFiles = directory.listFiles();
// Check for count
if (listFiles.length > 0)
{
for (int i = 0; i < listFiles.length; i++)
{
String filePath = listFiles[i].getAbsolutePath();
if (IsSupportedFile(filePath))
{
// Add image path to array list
filePaths.add(filePath);
}
}
}
else
{
// image directory …
Run Code Online (Sandbox Code Playgroud) 我有高分辨率图像的问题.
我使用nodpi-drawable文件夹为1280x720图像,并使用此代码来缩放它.
public static Drawable scaleDrawable(Drawable d, int width, Activity cxt)
{
BitmapDrawable bd = (BitmapDrawable)d;
double oldWidth = bd.getBitmap().getWidth();
double scaleFactor = width / oldWidth;
int newHeight = (int) (d.getIntrinsicHeight() * scaleFactor);
int newWidth = (int) (oldWidth * scaleFactor);
Drawable drawable = new BitmapDrawable(cxt.getResources(),MainScreen.getResizedBitmap(bd.getBitmap(),newHeight,newWidth));
BitmapDrawable bd2 = (BitmapDrawable)drawable;
return drawable;
}
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = …
Run Code Online (Sandbox Code Playgroud) 由于谷歌在M Developer Preview中宣布了不同应用的上下文搜索"Now on Tap"功能,所以我只想测试该功能.我已经将模拟器(使用genymotion)更新为M.但我无法测试这个.
有人有想法吗?
我确信,这个问题代码必须在这个网站上提出.但我无法搜索,这是基本的问题,但由于我的基本概念不佳,我没有得到它 -
public class A {
A obj = new A();
public static void main(String arg[])
{
A ob = new A();
}
}
Run Code Online (Sandbox Code Playgroud)
它给java.lang.StackOverflowError
,为什么?