我使用此代码从相机获取图片并将其放在imageview上:
private void openCamera()
{
mMediaUri =getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(photoIntent, REQUEST_TAKE_PHOTO);
// dialog.dismiss();
}
private Uri getOutputMediaFileUri(int mediaTypeImage)
{
//check for external storage
if(isExternalStorageAvaiable())
{
File mediaStorageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
String fileName = "";
String fileType = "";
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new java.util.Date());
fileName = "IMG_"+timeStamp;
fileType = ".jpg";
File mediaFile;
try
{
mediaFile = File.createTempFile(fileName,fileType,mediaStorageDir);
Log.i("st","File: "+Uri.fromFile(mediaFile));
}
catch (IOException e)
{
e.printStackTrace();
Log.i("St","Error creating file: " + mediaStorageDir.getAbsolutePath() +fileName +fileType);
return null;
} …Run Code Online (Sandbox Code Playgroud) 我已经放了一些EditText,RecyclerView因为我需要得到一些价值.实施是这样的:
<android.support.v7.widget.RecyclerView
android:layout_below="@id/firstrow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/rectable"
android:layout_marginLeft="@dimen/table_margin"
android:layout_marginRight="@dimen/table_margin"
android:layout_marginBottom="300dp" />
Run Code Online (Sandbox Code Playgroud)
这是自定义xml与一些editText:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="60dp ">
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/description"
android:layout_weight="1"
android:textColor="@color/black" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:id="@+id/weight"
android:focusable="true"
style="@style/DefaultEditCellStyle" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:id="@+id/arm"
android:focusable="true"
style="@style/DefaultEditCellStyle" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:focusable="true"
android:id="@+id/moment"
style="@style/DefaultEditCellStyle" />
Run Code Online (Sandbox Code Playgroud)
实际上,当我点击EditText它打开键盘,失去焦点并立即关闭键盘,所以不可能写入这些.我也试过读其他问题,把这个:
recyclerView.setFocusable(true);
recyclerView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
recyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
但是,在不同的情况下listview,它不起作用.
我怎么能解决这个问题?谢谢
我正在使用Dagger开始我的项目.我制作了这个模块:
@Module
public class FirebaseModule {
@Provides @Singleton
public FirebaseUser provideCurrentUser(){
return FirebaseAuth.getInstance().getCurrentUser();
}
@Provides @Singleton
public DatabaseReference provideDatabaseReference(){
return FirebaseDatabase.getInstance().getReference();
}
@Provides @Singleton
public FirebaseAuth provideFirebaseAuth(){
return FirebaseAuth.getInstance();
}
}
Run Code Online (Sandbox Code Playgroud)
还有这个:
@Module
public class AppModule
{
private HappyParkApp app;
public AppModule(HappyParkApp app) {
this.app = app;
}
@Provides
public HappyParkApp providesApp()
{
return this.app;
}
@Provides
public Context getAppContext(){
return this.app;
}
}
Run Code Online (Sandbox Code Playgroud)
我也做了这个组件:
@Singleton
@Component(modules = {AppModule.class,
FirebaseModule.class})
public interface AppComponent {
void inject(MainActivity activity);
}
Run Code Online (Sandbox Code Playgroud)
这是应用程序中实现的appComponent:
public …Run Code Online (Sandbox Code Playgroud) 我需要这样做:使用CardView的RecycleView.第一张卡是静态的:它显示"此订单的详细信息".第一个之后的其他卡是动态的.所以我决定做这个代码:
public class DocumentTypeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
private List<DocumentType> document; //lista di card da riempire
private Context context;
public DocumentTypeAdapter(List<DocumentType>document, Context context)
{
this.document = document;
this.context = context;
}
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view;
if(viewType == 0)
{
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_info, parent, false);
ViewSimple simpleView = new ViewSimple(view);
return simpleView;
}
else
{
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_info, parent, false);
DocumentTypeViewHolder documentTypeViewHolder = new DocumentTypeViewHolder(view);
return documentTypeViewHolder;
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用RealmRecyclerViewAdapter.我的问题是实现一个Filterable不起作用.这是代码:
private class AirportAdapter extends RealmRecyclerViewAdapter<AirportR,RecyclerView.ViewHolder> implements Filterable
{
Context context;
OrderedRealmCollection<AirportR>listAirports;
public AirportAdapter(Context activity, OrderedRealmCollection<AirportR>airports)
{
super(activity,airports, true);
this.context = activity;
this.listAirports = airports;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.airport_show, parent,false);
AirportClass holder = new AirportClass(view);
return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
AirportR airportR = listAirports.get(position);
AirportClass mHolder = (AirportClass)holder;
mHolder.country.setText(airportR.getIsoCountry());
mHolder.name.setText(airportR.getName());
}
public Filter getFilter()
{
AirportFilter filter = new AirportFilter(this, listAirports);
return filter; …Run Code Online (Sandbox Code Playgroud) android filter realm android-filterable android-recyclerview
我使用React.js和Express.js作为Web服务器制作了我的webapp.React在package.json中与Express(现在)连接到Express:
"proxy": "http://localhost:5000/"
Run Code Online (Sandbox Code Playgroud)
在我的Express服务器中,我用它来处理会话:
const cookieSession = require('cookie-session');
Run Code Online (Sandbox Code Playgroud)
还有这个:
app.use(cookieSession({
name: 'parse-session',
secret: "SECRET_SIGNING_KEY",
maxAge: 15724800000
}));
Run Code Online (Sandbox Code Playgroud)
因此,当我使用登录到我的API时它工作正常,这是检查currentUser是否存在的代码:
return new Promise((resolve,reject)=>{
if(req.session.token){
console.log(req.session.token);
request({
uri:'http://myserver.herokuapp.com/parse/users/me',
headers: {
'X-Parse-Application-Id': 'my-app-id',
'X-Parse-Session-Token': req.session.token
},
json:true
}).then((userData) => {
if(userData){
resolve(userData);
}
}).catch((error) => {
reject(error);
});
}
Run Code Online (Sandbox Code Playgroud)
并且在React中调用它没有问题:
fetch('/user',{credentials:'include'})
.then((response)=>{
return response.json();
})
.then((body)=>{
if(body.user){
this.setState({logIn:true});
}
}).catch((error)=>{
console.log('My error:',error);
});
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试注销时:我在React上执行此操作:
axios.post('/logout').then((res)=>{
console.log(res);
}).catch((err)=>{
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
这是在Express上注销:
app.post('/logout',(req,res)=>{
if(req.session){
req.session.destroy((error)=>{
if(error){
console.log(error);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误信息:
TypeError: req.session.destroy is not …Run Code Online (Sandbox Code Playgroud) 用于回收视图的 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.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerAircraftAdd"
android:background="#FFF" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SALVA AEREO"
android:id="@+id/salvaereo"
android:textColor="#fff"
android:background="#29B6F6"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Run Code Online (Sandbox Code Playgroud)
这是我的 recyclerView 适配器:
public class AircraftAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
private static final int LOADING_IMAGE = 0;
private static final int SELECT_PICTURE = 111;
private static final int DETAIL_AIRCRAFT = 1;
private static final int DESCRIPTION = 2;
public static Bitmap bmp;
private Context context;
private String imm,mod,man,cat,cl,vel,auto,cons,pos,cost;
private ArrayList<String> arrayList;
public AircraftAdapter(Context …Run Code Online (Sandbox Code Playgroud) 我有两个列表科特林,同样大小的,foodObjects: MutableList<ParseObject>?和checked: MutableList<Boolean>?.我需要做一个for循环并从foodObjects每次元素checked为true 时获取objectId .所以在Java中就是这样:
for(int i = 0; i< foodObjects.size(); i++) {
//here
}
Run Code Online (Sandbox Code Playgroud)
但是在Kotlin,我不知道为什么,有一些问题.事实上,如果我这样做:
for(i in 0..foodObjects!!.size)
{
if (checked?.get(i) == true) {
objectsId?.add(foodObjects.get(i).objectId)
}
}
Run Code Online (Sandbox Code Playgroud)
我有IndexOutOfBoundsException:我不知道为什么,它继续循环也在foodObjects.size.我也可以使用过滤器和地图来做到这一点:
(0..foodObjects!!.size)
.filter { checked?.get(it) == true }
.forEach { objectsId?.add(foodObjects.get(it).objectId) }
Run Code Online (Sandbox Code Playgroud)
但我给出了同样的错误.如果出现以下情况,我需要停止使用它:
for(i in 0..foodObjects!!.size)
{
if(i < foodObjects.size) {
if (checked?.get(i) == true) {
objectsId?.add(foodObjects.get(i).objectId)
}
}
}
Run Code Online (Sandbox Code Playgroud)
让它工作.
每个人都可以告诉我为什么在Kotlin我需要这样做,在Java中它运作良好?
我用viewPager和TabLayout创建了我的布局:
public class HomeFragment extends Fragment
{
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 3 ;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.fragment_home, container,false);
viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager);
int [] drawables = {R.drawable.home,R.drawable.street,R.drawable.map};
Bundle bundle = new Bundle();
final SearchFragment searchFragment = new SearchFragment();
final CardFragment cardFragment = new CardFragment();
final MapFragment mapFragment = new MapFragment();
viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager())
{
public Fragment getItem(int position)
{
if(position == 0)
return …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我需要从相机加载图像。
这是我使用的代码:
private void openCamera()
{
mMediaUri =getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(photoIntent, REQUEST_TAKE_PHOTO);
}
private Uri getOutputMediaFileUri(int mediaTypeImage)
{
//check for external storage
if(isExternalStorageAvaiable())
{
File mediaStorageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
String fileName = "";
String fileType = "";
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new java.util.Date());
fileName = "IMG_"+timeStamp;
fileType = ".jpg";
File mediaFile;
try
{
mediaFile = File.createTempFile(fileName,fileType,mediaStorageDir);
Log.i("st","File: "+Uri.fromFile(mediaFile));
}
catch (IOException e)
{
e.printStackTrace();
Log.i("St","Error creating file: " + mediaStorageDir.getAbsolutePath() +fileName +fileType);
return null;
}
return …Run Code Online (Sandbox Code Playgroud)