小编mlz*_*lz7的帖子

将expandableListView添加到NavigationView

我有一个在xml中定义的菜单:

<group android:checkableBehavior="single" android:id="@+id/group">
    <item
        android:id="@+id/grades"
        android:icon="@drawable/ic_font_download_black_48dp"
        android:checked="false"
        android:title="Grades" >
        <menu>
            <item
                android:id="@+id/mp1"
                android:icon="@drawable/ic_looks_one_black_24dp"
                android:checked="false"
                android:title="MP1" />
            <item
                android:id="@+id/mp2"
                android:icon="@drawable/ic_looks_two_black_24dp"
                android:checked="false"
                android:title="MP2" />
            <item
                android:id="@+id/mp3"
                android:icon="@drawable/ic_font_download_black_48dp"
                android:checked="false"
                android:title="MP3" />
            <item
                android:id="@+id/mp4"
                android:icon="@drawable/ic_font_download_black_48dp"
                android:checked="false"
                android:title="MP4" />
        </menu>
    </item>
    <item
        android:id="@+id/schedule"
        android:icon="@drawable/ic_event_black_48dp"
        android:checked="false"
        android:title="Schedule" />
    <item
        android:id="@+id/attendance"
        android:icon="@drawable/ic_assignment_ind_black_48dp"
        android:checked="false"
        android:title="Attendance" />
    <item
        android:id="@+id/assignments"
        android:icon="@drawable/ic_assignment_black_48dp"
        android:checked="false"
        android:title="Assignments" />
    <item
        android:id="@+id/studentInfo"
        android:icon="@drawable/ic_account_circle_black_48dp"
        android:checked="false"
        android:title="Student Details" />
</group>
<group android:id="@+id/group2" android:checkableBehavior="single">
    <item
        android:id="@+id/placeholder"
        android:icon="@drawable/ic_android_black_48dp"
        android:checked="false"
        android:title="Placeholder" />
    <item
        android:id="@+id/placeholder2"
        android:icon="@drawable/ic_android_black_48dp"
        android:checked="false"
        android:title="Placeholder" />
</group>
Run Code Online (Sandbox Code Playgroud)

这会添加一个如下所示的子菜单: …

android android-layout

33
推荐指数
1
解决办法
3万
查看次数

android.widget.Toolbar无法转换为android.support.v7.widget.Toolbar

我有一个toolbar.xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark" />
Run Code Online (Sandbox Code Playgroud)

我的另一个活动布局包含一个include标记:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme">

<include
    layout="@layout/toolbar"
    android:id="@+id/tb">
</include>

<android.support.v7.widget.RecyclerView
    android:id="@+id/grade_list"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" />
Run Code Online (Sandbox Code Playgroud)

我在我的活动中实现了它,扩展了AppCompatActivity:

Toolbar toolbar;
    toolbar = (Toolbar)findViewById(R.id.tb);
    setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)

但是,当我运行我的应用程序时出现以下错误:

Error:(26, 29) error: incompatible types: android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar
Run Code Online (Sandbox Code Playgroud)

此外,当我在编辑器中查看我的布局时,收到以下消息:

Missing styles. Is the correct theme chosen for this layout?
Use the theme combo box above the layout to choose a different layout, or to fix the theme style references.
Failed to find …
Run Code Online (Sandbox Code Playgroud)

android android-layout

26
推荐指数
2
解决办法
4万
查看次数

RecyclerView中的CardView:填充时的动画

我有一个回收的视图,其中填充了CardView布局.我注意到在许多应用程序中,这些项目有一个很好的动画入口,而不是像我们目前在我的应用程序中那样突然出现.我想要实现的一个例子如下所示: 在此输入图像描述

我如何使用swipeRefreshListener/adapter来触发此动画?我如何通过我的适配器实现这一点?

注意:当RecyclerView首次使用CardView项目及其包含的数据填充时,我也需要触发此动画.

我的RecyclerView适配器如下所示:

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {

private String[] mDataset;
private String[] mClassDataset;
private int lastPosition = -1;
private Context context;

View view;


public static class ViewHolder extends RecyclerView.ViewHolder {

    public TextView mTextView;
    public TextView mClassDataView;
    CardView container;


    public ViewHolder(View itemView) {
        super(itemView);
        mTextView = (TextView)itemView.findViewById(R.id.grade);
        mClassDataView = (TextView)itemView.findViewById(R.id.class_name);
        container = (CardView)itemView.findViewById(R.id.card_view);
    }
}

public RecyclerAdapter(String[] myDataset, String[] classData, Context context) {
    mDataset = myDataset;
    mClassDataset = classData;
    this.context = context;

}

@Override
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, …
Run Code Online (Sandbox Code Playgroud)

android android-layout

21
推荐指数
1
解决办法
3万
查看次数

将navigationView与tabLayout一起使用

所以我最近一直在努力更新我的应用程序以使用新的材料设计支持库.我的应用程序有一个主要活动,其中包含drawerLayout和导航视图.app的主要内容通过片段显示在frameLayout中.但是,我现在正在尝试将材质选项卡添加到导航抽屉的一个片段中.但是,我不确定如何实现这一点,同时保持我的片段在导航抽屉功能.我想要实现的一个很好的例子如下所示:

在此输入图像描述

在这个应用程序(谷歌播放音乐)中,只有一些导航抽屉的项目有标签而有些则没有.所以我的问题是,我将如何实现这一点?(不寻找代码,只是概述我的布局应该如何组织)

回顾/澄清:我有一个主要布局,其中包含frameLayout(用于我的应用程序的内容),以及一个navigationView(用于导航不同的项目片段).然后我有一个监听器,用项目的相应片段替换主布局的frameLayout.现在,我需要为这些片段中的一个添加制表符(在4个其他片段之间导航).我也使用工具栏,我将其作为单独的布局包含在内.

任何建议表示赞赏.如果我的描述有点令人困惑,我很抱歉; 我会澄清任何必要的细节.

android android-layout android-fragments

17
推荐指数
2
解决办法
6800
查看次数

如何将Selendroid添加到Android工作室进行网页抓取?

在回答之前请看下面的编辑!

我正在尝试使用Selenium设置动态网络报废,但是,我似乎无法找到必要的gradle依赖项/ lib文件添加到我的项目中.我查看了Selendroid/Selenium的网站,但无法找到必要的配置信息.我假设我需要webdriver,因为我将要抓取网页数据.作为旁注,我发现在找到与Android不兼容的HtmlUnit之后使用Selendroid,并且在找不到可行的替代品之后.所有帮助表示赞赏.

(解决这个问题的其他问题仍然没有答案)

编辑:所以使用Exeon的建议,我找到了Selendroid的以下依赖项:

__PRE__

但是,在运行我的应用程序时,我收到以下错误(重复大约10次):

__PRE__

注意,我也尝试使用以下内容:

__PRE__

但我遇到了同样的错误......

java android android-studio selendroid

13
推荐指数
1
解决办法
1359
查看次数

在训练的张量流网络中获得所有输入的相同预测值

我创建了一个张量流网络,用于从该数据集中读取数据(注意:此数据集中的信息仅用于测试目的而不是真实的):在此输入图像描述我正在尝试建立一个张量流网络,旨在从根本上预测"已退出"列中的值.我的网络构造为采用11个输入,通过relu激活通过2个隐藏层(每个6个神经元),并使用sigmoid激活函数输出单个二进制值,以产生概率分布.我正在使用梯度下降优化器和均方误差成本函数.但是,在我的训练数据训练网络并预测我的测试数据之后,我的所有预测值都大于0.5意味着可能是真的,我不确定问题是什么:

X_train, X_test, y_train, y_test = train_test_split(X_data, y_data, test_size=0.2, random_state=101)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.fit_transform(X_test)

training_epochs = 200
n_input = 11
n_hidden_1 = 6
n_hidden_2 = 6
n_output = 1

def neuralNetwork(x, weights):
     layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
     layer_1 = tf.nn.relu(layer_1)
     layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])
     layer_2 = tf.nn.relu(layer_2)
     output_layer = tf.add(tf.matmul(layer_2, weights['output']), biases['output'])
     output_layer = tf.nn.sigmoid(output_layer)
     return output_layer

weights = {
    'h1': tf.Variable(tf.random_uniform([n_input, n_hidden_1])),
    'h2': tf.Variable(tf.random_uniform([n_hidden_1, n_hidden_2])),
    'output': tf.Variable(tf.random_uniform([n_hidden_2, n_output]))
}

biases = { …
Run Code Online (Sandbox Code Playgroud)

python neural-network tensorflow

8
推荐指数
1
解决办法
773
查看次数

在 redux 操作中查询 api 时的无限循环

我正在尝试通过 redux-thunk 操作查询我的 Firebase 后端,但是,当我在使用 的初始渲染中这样做时useEffect(),我最终遇到此错误:

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
Run Code Online (Sandbox Code Playgroud)

我的操作只是返回一个 Firebase 查询快照,然后我在我的减速器中收到了它。我使用钩子来调度我的动作:

export const useAnswersState = () => {
    return {
        answers: useSelector(state => selectAnswers(state)),
        isAnswersLoading: useSelector(state => selectAnswersLoading(state))
    }
}

export const useAnswersDispatch = () => {
    const dispatch = useDispatch()
    return {
        // getAnswersData is a redux-thunk action that returns …
Run Code Online (Sandbox Code Playgroud)

javascript firebase reactjs redux react-redux

8
推荐指数
1
解决办法
1516
查看次数

需要帮助登录网站并检索信息

我已经阅读了许多类似的问题,但我仍然坚持登录我的学校成绩簿(https://parents.mtsd.k12.nj.us/genesis/parents)来检索数据.我的网络课程如下所示:

public class WebLogin {

    public String login(String username, String password, String url) throws IOException {
        URL address = new URL(url);

        HttpURLConnection connection = (HttpURLConnection) address.openConnection();
        connection.setDoOutput(true);
        connection.setRequestProperty("j_username", username);
        connection.setRequestProperty("j_password", password);
        connection.setRequestProperty("__submit1__","Login");

        InputStream response = connection.getInputStream();
        Document document = Jsoup.parse(response, null, "");

        //don't know what to do here!

        return null;
    }
 }
Run Code Online (Sandbox Code Playgroud)

我不知道如何处理InputStream或者我是否要正确登录,再一次,我已经阅读了几个在线资源以尝试理解这个概念,但我仍然感到困惑.任何帮助表示赞赏!

更新:所以现在我了解基本过程,我知道我必须做什么.当使用Jsoup来处理连接时,我知道你可以这样做:

    Connection.Response res = Jsoup.connect("---website---")
                .data("j_username", username, "j_password", password)
                .followRedirects(true)
                .method(Method.POST)
                .execute();
Run Code Online (Sandbox Code Playgroud)

但是,我仍然有点困惑如何实际发送数据(例如用户的用户名/密码到HttpURLConnection网站,以及如何实际存储获得的cookie ...否则,帮助非常有用,其他一切都很好

java httpurlconnection

6
推荐指数
1
解决办法
360
查看次数

二叉搜索树删除中基本情况的目的

我正在学习Python 3中的算法和数据结构课程,我的讲师最近向我们介绍了二叉搜索树.但是,我无法理解删除算法.下面是我们教授的实现,但是当我最初编写自己的演绎时,我没有包含"基本案例",它仍然有效:

def remove(self, data):
    if self.root:
        self.root = self.remove_node(data, self.root)

def remove_node(self, data, node):
     if node is None:
        return node
    if data < node.data:
        node.leftChild = self.remove_node(data, node.leftChild)
    elif data > node.data:
        node.rightChild = self.remove_node(data, node.rightChild)
    else:
        if not node.rightChild and not node.leftChild:
            print('removing leaf node')
            del node
            return None
        if not node.leftChild:
            print('removing node with single right child')
            tempNode = node.rightChild
            del node
            return tempNode
        elif not node.rightChild:
            print('removing node with single left child')
            tempNode = node.leftChild
            del …
Run Code Online (Sandbox Code Playgroud)

python tree recursion

5
推荐指数
1
解决办法
277
查看次数

raft 节点如何了解对等节点?

我刚刚完成了草稿纸并开始实施。然而,我意识到我对一个关键细节有点困惑。raft 节点 \xe2\x80\x9c\xe2\x80\x9d 如何了解其对等节点?我在论文中没有看到\xe2\x80\x99 提到这一点,所以我认为它是特定于实现的,但在我看来,它导致了许多问题:

\n
    \n
  • raft集群的大小是静态的吗?由于每个节点都必须了解其他所有对等点(以便发送 RPC),因此新节点如何加入现有集群?现有节点如何了解这个新节点?
  • \n
  • 初始化时是否必须将每个节点\xe2\x80\x99s 网络位置硬编码到每个其他节点中?节点如何知道将 RPC 发送到哪里?
  • \n
\n

非常感谢对此的一些帮助。我真的很想完全理解 raft,并且很高兴能够实现它,但我对系统架构的这一部分有点迷失。对我来说,节点应该使用硬编码的网络位置进行静态配置似乎并不正确,因为在现实世界中,我绝对可以想象需要将新节点添加到现有集群中。谢谢!

\n

distributed-system consensus raft

5
推荐指数
1
解决办法
946
查看次数

对通知单击执行操作

我有一个应用程序,它在服务中使用持久通知并在后台运行。在此服务运行时,我需要能够在单击通知时调用方法/执行某些操作。但是,我不确定如何实现这一点。我已经阅读了许多类似的问题/答案,但是没有一个答案明确或适合我的目的。 这个SO 问题接近我想要达到的目标,但选择的答案很难理解。

我的服务/通知在我的 BackgroundService 类的 onCreate() 方法中启动...

Notification notification = new Notification();
    startForeground(1, notification);
    registerReceiver(receiver, filter);
Run Code Online (Sandbox Code Playgroud)

这个服务是从我的主要活动的按钮点击启动的:

final Intent service = new Intent(Main.this, BackgroundService.class);

bStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if((counter % 2) == 0){

                bStart.setText("STOP");
                startService(service);

            }else {
                bStart.setText("BEGIN");
                stopService(service);
            }

            counter++;

        }
Run Code Online (Sandbox Code Playgroud)

任何建议表示赞赏

android

2
推荐指数
1
解决办法
6170
查看次数